align caller-supplied buffer in value_stack::stack - #1193
Open
Ramya-9353 wants to merge 1 commit into
Open
Conversation
|
An automated preview of the documentation is available at https://1193.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-28 19:43:54 UTC |
|
GCOVR code coverage report https://1193.json.prtest2.cppalliance.org/gcovr/index.html Build time: 2026-08-28 19:58:43 UTC |
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Repro: hand any of the buffer-taking parser / stream_parser / value_stack constructors a buffer that is not aligned for
value(buf + 1, a heap block, a sub-buffer) and parse a small array. UBSan reportsconstructor call on misaligned address ... for type boost::json::value, which requires 8 byte alignmentatdetail/value.hpp:229, viavalue_stack::stack::push.Cause:
value_stack::stackstoresvalueobjects in the caller-owned buffer but reinterprets it asvalue*without aligning the pointer.static_resource::do_allocateandmonotonic_resourceboth align a caller buffer throughstd::align; this constructor was the one that skipped it, and the buffer overloads document the parameter only as "a pointer to valid storage".Fix: align the buffer up to
alignof(value)withstd::align, keepingmin_size_ * sizeof(value)usable bytes, and fall back to the memory resource when the aligned region is too small.Regression test walks every misalignment of a value-sized buffer and parses
[1,2,3]; the odd offsets trip UBSan before the change and pass after.