Browse Source

MultipartParser should respect read position

This commit ensures that the MultipartParser takes a buffer's read
position into account.

Closes gh-31110
pull/31244/head
Arjen Poutsma 1 year ago
parent
commit
81ebc3a6f3
  1. 9
      spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartParser.java

9
spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartParser.java

@ -523,7 +523,7 @@ final class MultipartParser extends BaseSubscriber<DataBuffer> { @@ -523,7 +523,7 @@ final class MultipartParser extends BaseSubscriber<DataBuffer> {
if (logger.isTraceEnabled()) {
logger.trace("Boundary found @" + endIdx + " in " + buffer);
}
int len = endIdx - this.boundaryLength + 1;
int len = endIdx - this.boundaryLength + 1 - boundaryBuffer.readPosition();
if (len > 0) {
// whole boundary in buffer.
// slice off the body part, and flush
@ -538,10 +538,11 @@ final class MultipartParser extends BaseSubscriber<DataBuffer> { @@ -538,10 +538,11 @@ final class MultipartParser extends BaseSubscriber<DataBuffer> {
DataBufferUtils.release(boundaryBuffer);
DataBuffer prev;
while ((prev = this.queue.pollLast()) != null) {
int prevLen = prev.readableByteCount() + len;
int prevByteCount = prev.readableByteCount();
int prevLen = prevByteCount + len;
if (prevLen > 0) {
// slice body part of previous buffer, and flush it
DataBuffer body = prev.split(prevLen);
DataBuffer body = prev.split(prevLen + prev.readPosition());
DataBufferUtils.release(prev);
enqueue(body);
flush();
@ -550,7 +551,7 @@ final class MultipartParser extends BaseSubscriber<DataBuffer> { @@ -550,7 +551,7 @@ final class MultipartParser extends BaseSubscriber<DataBuffer> {
else {
// previous buffer only contains boundary bytes
DataBufferUtils.release(prev);
len += prev.readableByteCount();
len += prevByteCount;
}
}
}

Loading…
Cancel
Save