From 41d6307c179f267cbf45adaf216f8380920dec34 Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Tue, 18 Oct 2022 22:07:41 +0100 Subject: [PATCH] LibHTTP: Fix not consuming the last byte of body in from_raw_request `index + 1` was not correct. For example, if the body has two bytes, we would consume the first byte and increment the index. We then add one to the index and see it's equal to the size, so we take this one byte and set the body result to it. The while loop would still continue and we consume the second byte, adding it to the temporary buffer. We see that the index is above the size, so we don't update the body, dropping the last byte on the floor. --- Userland/Libraries/LibHTTP/HttpRequest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibHTTP/HttpRequest.cpp b/Userland/Libraries/LibHTTP/HttpRequest.cpp index dc1928a104..fa43b6585e 100644 --- a/Userland/Libraries/LibHTTP/HttpRequest.cpp +++ b/Userland/Libraries/LibHTTP/HttpRequest.cpp @@ -175,7 +175,7 @@ Optional HttpRequest::from_raw_request(ReadonlyBytes raw_request) break; case State::InBody: buffer.append(consume()); - if (index + 1 == raw_request.size()) { + if (index == raw_request.size()) { // End of data, so store the body auto maybe_body = ByteBuffer::copy(buffer); // FIXME: Propagate this error somehow.