Skip to content

account for completed utf-8 sequence in parse_string size limit - #1185

Closed
Ramya-9353 wants to merge 3 commits into
boostorg:developfrom
Ramya-9353:parse-string-str8-total
Closed

account for completed utf-8 sequence in parse_string size limit#1185
Ramya-9353 wants to merge 3 commits into
boostorg:developfrom
Ramya-9353:parse-string-str8-total

Conversation

@Ramya-9353

Copy link
Copy Markdown
Contributor

Repro: feed a multi-byte UTF-8 string to stream_parser one byte at a time, so each character completes across a write_some boundary; max_string_size/max_key_size is not applied to it and on_string_part/on_key_part report a total that omits those bytes.
Cause: the str8 resume path in parse_string (completing a UTF-8 sequence split across a chunk) emits seq_.length() bytes to the handler without bounds-checking them or adding them to total. do_str1 and parse_escaped both account before their handler calls; str8 was the gap.
Fix: on the str8 path, check seq_.length() against the remaining budget and add it to total before emitting, matching do_str1.

Regression test in test/limits.cpp drives split multi-byte strings and keys through stream_parser a byte at a time; the size limits are skipped before the change and enforced after.

@cppalliance-bot

cppalliance-bot commented Aug 11, 2026

Copy link
Copy Markdown

An automated preview of the documentation is available at https://1185.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-08-13 06:54:42 UTC

@cppalliance-bot

cppalliance-bot commented Aug 11, 2026

Copy link
Copy Markdown

GCOVR code coverage report https://1185.json.prtest2.cppalliance.org/gcovr/index.html
LCOV code coverage report https://1185.json.prtest2.cppalliance.org/genhtml/index.html
Coverage Diff Report https://1185.json.prtest2.cppalliance.org/diff-report/index.html

Build time: 2026-08-13 06:57:59 UTC

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.92%. Comparing base (3dd600f) to head (5a3cb6c).
⚠️ Report is 4 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1185      +/-   ##
===========================================
- Coverage    93.92%   93.92%   -0.01%     
===========================================
  Files           91       91              
  Lines         9290     9297       +7     
===========================================
+ Hits          8726     8732       +6     
- Misses         564      565       +1     
Files with missing lines Coverage Δ
include/boost/json/basic_parser_impl.hpp 98.67% <100.00%> (+<0.01%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3dd600f...5a3cb6c. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cppalliance-bot

Copy link
Copy Markdown

Comment thread test/limits.cpp Outdated
Comment thread test/limits.cpp Outdated
Comment thread test/limits.cpp Outdated
Comment thread test/limits.cpp Outdated
Comment thread include/boost/json/basic_parser_impl.hpp Outdated
@cppalliance-bot

Copy link
Copy Markdown

@grisumbras

Copy link
Copy Markdown
Member

So, coverage checks fail on this PR here: https://1185.json.prtest2.cppalliance.org/diff-report/include/boost/json/basic_parser_impl.hpp.html#NL1125

This shows that we do not have a test for when a key has a UTF-8 multibyte character, the parser suspends within it and then resumes. Can you please add a test for that as a separate commit, so that the PR's CI is green?

@Ramya-9353

Copy link
Copy Markdown
Contributor Author

Added in a separate commit: same feed shape as the key overflow test, but with string::max_size() - 2 filler bytes so the split character completes on the str8 resume path exactly at the limit and the key parses cleanly. That runs the on_key_part call the diff report flagged as uncovered. Passes locally under ASan/UBSan.

@cppalliance-bot

Copy link
Copy Markdown

@grisumbras

Copy link
Copy Markdown
Member

Merged as 5fad60c and c527374.

@grisumbras grisumbras closed this Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants