Skip to content

Commit 4472050

Browse files
committed
Discard bytes after Content-Length
When accepting an upload, discard any bytes after Content-Length. This ensures that handlers such as AsyncJson can safely allocate the correct sized buffer without needing to additionally check for overrun. Fixes #100
1 parent 7b6253c commit 4472050

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/WebRequest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ void AsyncWebServerRequest::_onData(void *buf, size_t len) {
167167
// A handler should be already attached at this point in _parseLine function.
168168
// If handler does nothing (_onRequest is NULL), we don't need to really parse the body.
169169
const bool needParse = _handler && !_handler->isRequestHandlerTrivial();
170+
// Discard any bytes after content length; handlers may overrun their buffers
171+
len = std::min(len, _contentLength - _parsedLength);
170172
if (_isMultipart) {
171173
if (needParse) {
172174
size_t i;

0 commit comments

Comments
 (0)