For the default Locale of en_US
, the following code:
MockHttpServletRequest request = new MockHttpServletRequest();
request.setContentType("İcharset=");
fails with:
java.lang.StringIndexOutOfBoundsException: begin 10, end 9, length 9
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4604)
at java.base/java.lang.String.substring(String.java:2707)
at java.base/java.lang.String.substring(String.java:2680)
at org.springframework.mock.web.MockHttpServletRequest.setContentType(MockHttpServletRequest.java:495)
The problem is that contentType.toLowerCase() changes the length of the String, so when using the index on the original String causes a StringIndexOutOfBoundsException
.
This is causing failures to be reported to Spring Security by the oss-fuzz project which generated random inputs for their test cases which resulted in this error being reported to Spring Security.
While the header is invalid it would be nice to be able to test invalid headers using the mock object.
Comment From: rstoyanchev
We actually fail in the handling of the parse exception, while trying to extract the charset, and as a result the original exception is lost. We should address that indeed.
Comment From: rstoyanchev
Fixed in 9c0b28ffdc813ab10f9262c4f6b6c25c4dbdf323, but commit refers to the wrong issue.