clamp count in string_impl::replace_unchecked#1166
Conversation
|
An automated preview of the documentation is available at https://1166.json.prtest2.cppalliance.org/libs/json/doc/html/index.html If more commits are pushed to the pull request, the docs will rebuild at the same URL. 2026-07-06 09:58:51 UTC |
|
GCOVR code coverage report https://1166.json.prtest2.cppalliance.org/gcovr/index.html Build time: 2026-07-06 10:10:21 UTC |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1166 +/- ##
========================================
Coverage 93.90% 93.90%
========================================
Files 91 91
Lines 9256 9257 +1
========================================
+ Hits 8692 8693 +1
Misses 564 564
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
|
|

Repro:
boost::json::string("hello").replace(0, 100, 0, 'x')— the count exceedssize() - pos.Cause:
string_impl::replace_uncheckeddoesn't clampn1tosize() - pos, socurr_size - pos - n1 + 1underflows and thememmoveruns a near-SIZE_MAXlength out of bounds (ASAN:negative-size-paramat string_impl.ipp:409). Overload (4)string::replace(pos, count, count2, ch)forwardscountunchanged, though it is documented to replacestd::min(count, size() - pos)characters. Thestring_viewoverload already clamps viastring_impl::replace.Fix: clamp
n1tosize() - pos, matchingstring_impl::replace.