Skip to content

Commit 8f13031

Browse files
committed
MultipartParser should respect read position
This commit ensures that the MultipartParser takes a buffer's read position into account. Closes gh-31110
1 parent 54c4f1b commit 8f13031

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public void onNext(DataBuffer buffer) {
523523
if (logger.isTraceEnabled()) {
524524
logger.trace("Boundary found @" + endIdx + " in " + buffer);
525525
}
526-
int len = endIdx - this.boundaryLength + 1;
526+
int len = endIdx - this.boundaryLength + 1 - boundaryBuffer.readPosition();
527527
if (len > 0) {
528528
// whole boundary in buffer.
529529
// slice off the body part, and flush
@@ -538,10 +538,11 @@ else if (len < 0) {
538538
DataBufferUtils.release(boundaryBuffer);
539539
DataBuffer prev;
540540
while ((prev = this.queue.pollLast()) != null) {
541-
int prevLen = prev.readableByteCount() + len;
541+
int prevByteCount = prev.readableByteCount();
542+
int prevLen = prevByteCount + len;
542543
if (prevLen > 0) {
543544
// slice body part of previous buffer, and flush it
544-
DataBuffer body = prev.split(prevLen);
545+
DataBuffer body = prev.split(prevLen + prev.readPosition());
545546
DataBufferUtils.release(prev);
546547
enqueue(body);
547548
flush();
@@ -550,7 +551,7 @@ else if (len < 0) {
550551
else {
551552
// previous buffer only contains boundary bytes
552553
DataBufferUtils.release(prev);
553-
len += prev.readableByteCount();
554+
len += prevByteCount;
554555
}
555556
}
556557
}

0 commit comments

Comments
 (0)