Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 5 additions & 2 deletions src/main/java/io/fusionauth/http/io/MultipartStream.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, FusionAuth, All Rights Reserved
* Copyright (c) 2022-2023, FusionAuth, All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -311,7 +311,10 @@ private void readPart(Map<String, HeaderValue> headers, Map<String, List<String>
processor.process(current, partialBoundary);
}

reload(boundary.length + 2); // Minimum is at least a full boundary
// Minimum is at least a full boundary
if (!reload(boundary.length + 2)) {
throw new ParseException("Invalid multipart body. Ran out of data while processing.");
}
} else {
processor.process(current, boundaryIndex);
current = boundaryIndex;
Expand Down
28 changes: 27 additions & 1 deletion src/test/java/io/fusionauth/http/io/MultipartStreamTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, FusionAuth, All Rights Reserved
* Copyright (c) 2022-2023, FusionAuth, All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,11 +25,37 @@
import java.util.Map;

import io.fusionauth.http.FileInfo;
import io.fusionauth.http.ParseException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;

/**
* @author Brian Pontarelli
*/
public class MultipartStreamTest {
@DataProvider(name = "badBoundary")
public Object[][] badBoundary() {
return new Object[][]{
{"""
------WebKitFormBoundaryTWfMVJErBoLURJIe\r
Content-Disposition: form-data; name="foo"\r
\r
bar----WebKitFormBoundaryTWfMVJErBoLURJIe--"""},
{"""
------WebKitFormBoundaryTWfMVJErBoLURJIe\r
Content-Disposition: form-data; name="foo"\r
\r
bar------WebKitFormBoundaryTWfMVJErBoLURJIe--"""}
};
}

@Test(dataProvider = "badBoundary", expectedExceptions = ParseException.class, expectedExceptionsMessageRegExp = "Invalid multipart body. Ran out of data while processing.")
public void bad_boundaryParameter(String boundary) throws IOException {
new MultipartStream(new ByteArrayInputStream(boundary.getBytes()), "----WebKitFormBoundaryTWfMVJErBoLURJIe".getBytes(), 1024)
.process(new HashMap<>(), new LinkedList<>());
}

@Test
public void boundaryInParameter() throws IOException {
ByteArrayInputStream is = new ByteArrayInputStream("""
Expand Down