Skip to content

Commit

Permalink
Corrupt multipart should not hang SynchronossPartHttpMessageReader
Browse files Browse the repository at this point in the history
This commit notifies the Synchronoss listener that the buffer stream
has ended.

Closes gh-23768
  • Loading branch information
poutsma committed Nov 7, 2019
1 parent 5d2fc2f commit bf36f49
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ protected void hookOnError(Throwable ex) {
}
}

@Override
protected void hookOnComplete() {
if (this.listener != null) {
this.listener.onAllPartsFinished();
}
}

@Override
protected void hookFinally(SignalType type) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Map;
Expand Down Expand Up @@ -46,6 +47,7 @@
import org.springframework.util.MultiValueMap;

import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.core.ResolvableType.forClassWithGenerics;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
Expand Down Expand Up @@ -142,6 +144,24 @@ void readPartsWithoutDemand() {
subscriber.cancel();
}

@Test
void gh23768() throws IOException {
ReadableByteChannel channel = new ClassPathResource("invalid.multipart", getClass()).readableChannel();
Flux<DataBuffer> body = DataBufferUtils.readByteChannel(() -> channel, this.bufferFactory, 1024);

MediaType contentType = new MediaType("multipart", "form-data",
singletonMap("boundary", "NbjrKgjbsaMLdnMxMfDpD6myWomYc0qNX0w"));
ServerHttpRequest request = MockServerHttpRequest.post("/")
.contentType(contentType)
.body(body);

Mono<MultiValueMap<String, Part>> parts = this.reader.readMono(PARTS_ELEMENT_TYPE, request, emptyMap());

StepVerifier.create(parts)
.assertNext(result -> assertThat(result).isEmpty())
.verifyComplete();
}

@Test
void readTooManyParts() {
testMultipartExceptions(reader -> reader.setMaxParts(1), ex -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--NbjrKgjbsaMLdnMxMfDpD6myWomYc0qNX0w
Content-Disposition: form-data; name="part-00-name"

post-payload-text-23456789ABCDEF:post-payload-0001-3456789ABCDEF:post-payload-0002-3456789ABCDEF:post-payload-0003-3456789ABCDEF
--NbjrKgjbsaMLdnMxMfDpD6myWomYc

0 comments on commit bf36f49

Please sign in to comment.