Repository navigation
fix(http): parse Content-Length as i64 and cap it before any arithmetic - #3737
Conversation
A huge Content-Length overflowed the 32-bit request length and crashed the server. The client chunk size parser gets the same widening.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 8 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
sha=7be49b350c3a9ed17ac8cd27056d4b33b9d2db1a
🤖 Salam AI reviewVerdict: ✅ Good to merge commit SummaryThe pull request fixes a denial-of-service in the HTTP server by parsing Content-Length into an i64 instead of a saturating 32-bit int, and by checking the body cap and integer overflow before any length arithmetic on both read paths. The client chunk-size parsers in raw.salam are widened the same way. The change is focused and the new test cases match the described expected statuses. What changed
Review
TestsThe added cases exercise 10 through 15 digit values and a cap at the int maximum, all expecting 413, which directly covers the previously crashing inputs. The existing RisksThe first read path still does not free
|
The server parsed Content-Length with str ToInt, which saturates at 2147483647, then added it to the header length in a 32-bit int. Values from about 2^31 up to 15 digits wrapped negative and the first-read path sliced the buffer at a negative offset before the body cap was checked, so one request could crash the server.
Content-Length is now parsed into an i64 with no saturation, and anything over SetMaxBodyBytes (or that would not fit with the header) gets 413 before any length arithmetic, on both read paths. Duplicate Content-Length comparison uses the exact value too. The client chunk size parsers in raw.salam get the same widening, so a hostile chunk size can no longer go negative.
Tested: tests/en/general/net_http_limits now covers 10 to 15 digit values plus a cap at the int maximum (all 413; the server crashed on these before), and net_http_client_safety still passes.