flag out-of-range Content-Length in get_header_value_u64#2494
flag out-of-range Content-Length in get_header_value_u64#2494metsw24-max wants to merge 2 commits into
Conversation
|
@metsw24-max thank you for the PR. However, it causes lots of CI errors.... |
|
Sorry about that. Every failure was the same test: OpenStreamMalformedContentLength.OutOfRange asserted the old lenient behaviour, where an out-of-range Content-Length silently clamps to ULLONG_MAX and the stream still opens. With this change the value is flagged invalid, so open_stream now fails cleanly, matching the not-a-number case next to it. I've updated that test's expectation; its original point (no crash from std::stoull) still holds since the process just gets an invalid handle. Ran the OpenStream, GetHeaderValue and BodyReader suites locally with the CI flags and they're green, so CI should be sorted now. |
1e545d4 to
f648fd1
Compare
|
CI is green now, all 27 checks. After the test fix there was still one red job, ubuntu (mbedtls), but the failure was SSLClientTest.SetCaCertStoreNativeVerifiesLocalServer, a loopback TLS test this change doesn't touch. It binds a fixed port under the parallel runner and master has had the odd one-off mbedtls failure recently, so it looks like a flake; retriggering the run passed everything. |
|
Merged into master as 3adc525 (and the two preceding commits), with the parsing swapped from strtoull to the existing detail::from_chars for size_t-width overflow detection. Thanks for catching this and for the clear write-up on the request-smuggling risk! |
|
@metsw24-max thank you for your contribution. I decided to use |
Out-of-range
Content-Lengthsilently accepted inget_header_value_u64The value is parsed with
strtoullwhoseerrnois never checked and the 64-bit result is cast straight tosize_t, so a length pastULLONG_MAXsaturates toSIZE_MAXwhile one above2^32truncates on 32-bit builds, and in both casesis_invalid_valuestays clear soread_contentand the streaming client use the bogus framing length instead of rejecting it (on 32-bit the truncatedContent-Lengthdesyncs the next request on a keep-alive connection). The siblingdetail::from_charsalready reportsresult_out_of_range, so this flags the same condition here whenerrnoisERANGEor thesize_tcast loses information, returningSIZE_MAXso the existing> 0andmax_size()guards still see it as oversized.