Skip to content

Commit

Permalink
MultipartParser should respect read position
Browse files Browse the repository at this point in the history
This commit ensures that the MultipartParser takes a buffer's read
position into account.

Closes gh-31110
  • Loading branch information
poutsma committed Sep 15, 2023
1 parent 54c4f1b commit 8f13031
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public void onNext(DataBuffer buffer) {
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
Expand All @@ -538,10 +538,11 @@ else if (len < 0) {
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();
Expand All @@ -550,7 +551,7 @@ else if (len < 0) {
else {
// previous buffer only contains boundary bytes
DataBufferUtils.release(prev);
len += prev.readableByteCount();
len += prevByteCount;
}
}
}
Expand Down

0 comments on commit 8f13031

Please sign in to comment.