Repository navigation
Fix chunk_extensions state consistency and empty input handling - #3137
Conversation
| if(! name.empty()) | ||
| s_.append(name.data(), name.size()); |
There was a problem hiding this comment.
The if (!name.empty()) condition is unnecessary because s_.append(name.data(), name.size()); is well-defined even when name is empty. The same check appears in lines 598 and 610.
579b470 to
76da8e5
Compare
|
An automated preview of the documentation is available at https://3137.beast.prtest.cppalliance.org/libs/beast/doc/html/index.html If more commits are pushed to the pull request, the docs will rebuild at the same URL. 2026-11-15 06:55:58 UTC |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3137 +/- ##
===========================================
+ Coverage 93.88% 93.92% +0.03%
===========================================
Files 176 176
Lines 13977 13982 +5
===========================================
+ Hits 13123 13132 +9
+ Misses 854 850 -4
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
All three issues were reproduced against the latest Boost.Beast
developbranch before applying this patch:200ebae2d8021d3bdf1a713d4ffbaf1521c03dc7Bugs
Out-of-bounds read after a chunk-extension parse error
do_parse()constructsrange_incrementally. A malformed quoted value such as:stores the extension name before detecting that its value is invalid.
parse()previously rebuilt the serialized representation only after a successful parse:On failure, the partial
range_was retained. Iteration assumes that every entry contains both a name and a value:auto n = varint_read(it); it += n; n = varint_read(it);The second
varint_read()therefore reads past the end of the allocation. ASan reports a heap-buffer-overflow invarint_read().A failed parse now leaves the object empty, matching the documented behavior that parsing clears previous extensions.
Stale extensions remain iterable after
clear()clear()previously emptied only the serialized representation:Consequently:
produced an empty
str(), but iteration still returnedname=valuefrom the unchangedrange_.This also preserved any partial iteration entry left by a previous parse failure. Both internal representations are now cleared together.
Undefined behavior when inserting empty
string_viewvaluesThe insert overloads copied names and values unconditionally:
A default-constructed empty
string_viewhas a null data pointer and a size of zero. Passing that pointer tomemcpy(), even with a zero length, is reported by UBSan as an invalid null-pointer argument.The same concern applies to calls such as:
The copy operations are now skipped when the corresponding view is empty. Existing serialized and iteration behavior for empty inputs is preserved.
Testing
Before the patch, the focused cases on upstream commit
200ebae2produced:str()that still iterated the extension cleared byclear();string_view.After the patch:
beast.http.chunk_encodeunit suite passes: