Skip to content

Commit d3d4098

Browse files
committed
Corrupt multipart should not hang SynchronossPartHttpMessageReader
This commit notifies the Synchronoss listener that the buffer stream has ended. Closes gh-23768 (cherry picked from commit bf36f49)
1 parent 32adf77 commit d3d4098

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

spring-web/src/test/java/org/springframework/http/codec/multipart/SynchronossPartHttpMessageReaderTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.File;
2020
import java.io.IOException;
21+
import java.nio.channels.ReadableByteChannel;
2122
import java.time.Duration;
2223
import java.util.Map;
2324
import java.util.function.Consumer;
@@ -44,6 +45,7 @@
4445
import org.springframework.util.MultiValueMap;
4546

4647
import static java.util.Collections.emptyMap;
48+
import static java.util.Collections.singletonMap;
4749
import static org.hamcrest.core.StringStartsWith.startsWith;
4850
import static org.junit.Assert.assertEquals;
4951
import static org.junit.Assert.assertFalse;
@@ -149,6 +151,24 @@ public void readPartsWithoutDemand() {
149151
subscriber.cancel();
150152
}
151153

154+
@Test
155+
public void gh23768() throws IOException {
156+
ReadableByteChannel channel = new ClassPathResource("invalid.multipart", getClass()).readableChannel();
157+
Flux<DataBuffer> body = DataBufferUtils.readByteChannel(() -> channel, this.bufferFactory, 1024);
158+
159+
MediaType contentType = new MediaType("multipart", "form-data",
160+
singletonMap("boundary", "NbjrKgjbsaMLdnMxMfDpD6myWomYc0qNX0w"));
161+
ServerHttpRequest request = MockServerHttpRequest.post("/")
162+
.contentType(contentType)
163+
.body(body);
164+
165+
Mono<MultiValueMap<String, Part>> parts = this.reader.readMono(PARTS_ELEMENT_TYPE, request, emptyMap());
166+
167+
StepVerifier.create(parts)
168+
.assertNext(result -> assertThat(result).isEmpty())
169+
.verifyComplete();
170+
}
171+
152172
@Test
153173
public void readTooManyParts() {
154174
testMultipartExceptions(reader -> reader.setMaxParts(1), ex -> {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
--NbjrKgjbsaMLdnMxMfDpD6myWomYc0qNX0w
2+
Content-Disposition: form-data; name="part-00-name"
3+
4+
post-payload-text-23456789ABCDEF:post-payload-0001-3456789ABCDEF:post-payload-0002-3456789ABCDEF:post-payload-0003-3456789ABCDEF
5+
--NbjrKgjbsaMLdnMxMfDpD6myWomYc

0 commit comments

Comments
 (0)