fix(runtime): close chunk-size cap-check overflow in FeedChunkSize

body_.size() + size could wrap size_t when an attacker-controlled chunk
size (up to 0xFFFFFFFFFFFFFFFF) was added to an already non-empty body,
making the body_cap_ comparison pass when it should reject with 413.
Check the remaining budget instead of the sum: reject if body_ already
exceeds the cap, or if the declared chunk size exceeds what's left.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-10-25 20:05:29 +01:00
co-authored by Claude Sonnet 5
parent 16a0bb0de4
commit 8093b598c3
+1 -1
View File
@@ -345,7 +345,7 @@ ParseResult Parser::FeedChunkSize() {
state_ = State::Trailers;
return ParseResult::NeedMore;
}
if (body_.size() + size > body_cap_) {
if (body_.size() > body_cap_ || size > body_cap_ - body_.size()) {
state_ = State::Failed;
return ParseResult::Error413;
}