garydgregory commented on code in PR #425:
URL:
https://github.com/apache/commons-fileupload/pull/425#discussion_r2181355328
##########
commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/MultipartInput.java:
##########
@@ -908,6 +908,18 @@ public byte readByte() throws IOException {
return buffer[head++];
}
+ /**
+ * The byte size of all headers that have been read.
+ */
+ private long totalHeaderSizeRead = 0L;
Review Comment:
Don't initialize to default value.
##########
commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/AbstractFileUploadTest.java:
##########
@@ -442,4 +443,75 @@ void testMultipleRelated() throws Exception {
assertEquals("text/plain", part2.getContentType());
assertNull(part2.getName());
}
+
+
+ @Test
+ public void testExceedTotalPartHeaderSizeLimit() throws IOException {
+ upload.setPartHeaderTotalSizeMax(250);
+ try {
+ // @formatter:off
+ final var fileItems = parseUpload(upload,
+ "-----1234\r\n" +
+ "Content-Disposition: "
+ + "form-data;
name=\"file\"; filename=\"foo.tab\"\r\n" +
+ "Content-Type:
text/whatever\r\n" +
+ "\r\n" +
+ "This is the content of the
file\n" +
+ "\r\n" +
+ "-----1234\r\n" +
+ "Content-Disposition:
form-data; name=\"field\"\r\n" +
+ "\r\n" +
+ "fieldValue\r\n" +
+ "-----1234\r\n" +
+ "Content-Disposition:
form-data; name=\"multi\"\r\n" +
+ "\r\n" +
+ "value1\r\n" +
+ "-----1234\r\n" +
+ "Content-Disposition:
form-data; name=\"multi\"\r\n" +
+ "Content-Type:
text/plain\r\n" +
+ "Content-ID: multi-id\r\n" +
+ "\r\n" +
+ "value2\r\n" +
+ "-----1234--\r\n");
+ // @formatter:on
+ fail("FileUploadSizeException expected!");
+ } catch (FileUploadSizeException fse) {
+ assertEquals(upload.getPartHeaderTotalSizeMax(),
fse.getPermitted());
+ }
+ }
+
+ @Test
+ public void testPassTotalPartHeaderSizeLimit() throws IOException {
+ upload.setPartHeaderTotalSizeMax(1 << 10);
+ try {
+ // @formatter:off
+ final var fileItems = parseUpload(upload,
+ "-----1234\r\n" +
+ "Content-Disposition: "
+ + "form-data;
name=\"file\"; filename=\"foo.tab\"\r\n" +
+ "Content-Type:
text/whatever\r\n" +
+ "\r\n" +
+ "This is the content of the
file\n" +
+ "\r\n" +
+ "-----1234\r\n" +
+ "Content-Disposition:
form-data; name=\"field\"\r\n" +
+ "\r\n" +
+ "fieldValue\r\n" +
+ "-----1234\r\n" +
+ "Content-Disposition:
form-data; name=\"multi\"\r\n" +
+ "\r\n" +
+ "value1\r\n" +
+ "-----1234\r\n" +
+ "Content-Disposition:
form-data; name=\"multi\"\r\n" +
+ "Content-Type:
text/plain\r\n" +
+ "Content-ID: multi-id\r\n" +
+ "\r\n" +
+ "value2\r\n" +
+ "-----1234--\r\n");
+ // @formatter:on
+ assertEquals(4, fileItems.size());
+ } catch (FileUploadSizeException fse) {
+ fail(fse);
Review Comment:
Don't catch and rethrow.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]