Skip to content

degroff/0.3.5.maintenance file manager #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Code review, cleanup
  • Loading branch information
robotdan committed Jul 7, 2025
commit 54cc99d8c886e8031be616c36bbfbac6d6d0d08d
5 changes: 1 addition & 4 deletions src/main/java/io/fusionauth/http/io/MultipartStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,7 @@ private boolean reload(int minimumToLoad) throws IOException {
start += end;

// Keep track of all bytes read for this multipart stream. Fail if the length has been exceeded.
if (read > 0) {
bytesRead += read;
}

bytesRead += read;
long maximumRequestSize = multipartConfiguration.getMaxRequestSize();
if (bytesRead > maximumRequestSize) {
String detailedMessage = "The maximum request size of multipart stream has been exceeded. The maximum request size is [" + maximumRequestSize + "] bytes.";
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/io/fusionauth/http/io/MultipartStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
import static org.testng.FileAssert.fail;

/**
* @author Brian Pontarelli
Expand Down Expand Up @@ -216,6 +217,23 @@ public void separateParts(@SuppressWarnings("unused") int index, byte[][] parts)
Files.delete(files.get(0).file);
}

@Test
public void truncated() throws IOException {
ByteArrayInputStream is = new ByteArrayInputStream("""
------WebKitFormBoundaryTWfMVJErBoLURJIe\r
""".getBytes());
Map<String, List<String>> parameters = new HashMap<>();
List<FileInfo> files = new LinkedList<>();
MultipartStream stream = new MultipartStream(is, "----WebKitFormBoundaryTWfMVJErBoLURJIe".getBytes(), fileManager, new MultipartConfiguration().withFileUploadPolicy(MultipartFileUploadPolicy.Allow));
try {
stream.process(parameters, files);
fail("Expected to fail with a ParseException");

} catch (ParseException e) {
assertEquals(e.getMessage(), "Invalid multipart body. Ran out of data while processing.");
}
}

public static class PartInputStream extends InputStream {
private final byte[][] parts;

Expand Down