Skip to content

align caller-supplied buffer in value_stack::stack - #1193

Open
Ramya-9353 wants to merge 1 commit into
boostorg:developfrom
Ramya-9353:value-stack-align-buffer
Open

align caller-supplied buffer in value_stack::stack#1193
Ramya-9353 wants to merge 1 commit into
boostorg:developfrom
Ramya-9353:value-stack-align-buffer

Conversation

@Ramya-9353

Copy link
Copy Markdown
Contributor

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 reports constructor call on misaligned address ... for type boost::json::value, which requires 8 byte alignment at detail/value.hpp:229, via value_stack::stack::push.

Cause: value_stack::stack stores value objects in the caller-owned buffer but reinterprets it as value* without aligning the pointer. static_resource::do_allocate and monotonic_resource both align a caller buffer through std::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) with std::align, keeping min_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.

@cppalliance-bot

Copy link
Copy Markdown

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

@cppalliance-bot

Copy link
Copy Markdown

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

Build time: 2026-08-28 19:58:43 UTC

@cppalliance-bot

Copy link
Copy Markdown

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.

2 participants