Skip to content

fix: throw when MessagePack size exceeds uint32 limit (#5320) - #5381

Open
ameliabarnabyhub wants to merge 2 commits into
nlohmann:developfrom
ameliabarnabyhub:fix/msgpack-size-limit-5320
Open

fix: throw when MessagePack size exceeds uint32 limit (#5320)#5381
ameliabarnabyhub wants to merge 2 commits into
nlohmann:developfrom
ameliabarnabyhub:fix/msgpack-size-limit-5320

Conversation

@ameliabarnabyhub

Copy link
Copy Markdown

Fixes #5320

to_msgpack() now throws out_of_range.412 when a string, array, binary, or object reports a size above UINT32_MAX, matching the documented MessagePack limit and the BSON fix pattern from #5314.

Adds a regression test using a container type that reports an oversized size() without allocating multi-gigabyte data.

Signed-off-by: ameliabarnabyhub <ameliabarnabyhub@users.noreply.github.com>
Signed-off-by: ameliabarnabyhub <ameliabarnabyhub@users.noreply.github.com>
*/
void assert_msgpack_size(const std::size_t size, const BasicJsonType* const context = nullptr) const
{
if (JSON_HEDLEY_UNLIKELY(!value_in_range_of<std::uint32_t>(size)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this test when this is only called when this is known to be true?

/*!
@throw out_of_range.412 if @a size exceeds the MessagePack uint32 length limit
*/
void assert_msgpack_size(const std::size_t size, const BasicJsonType* const context = nullptr) const

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is always passed a pointer, don't need the default argument.

@github-actions

Copy link
Copy Markdown

🔴 Amalgamation check failed! 🔴

The source code has not been amalgamated and/or formatted correctly.

📎 A ready-to-apply patch is attached to the failed workflow run as the amalgamation-patch artifact. Download it, then apply it locally from the repository root with:

git apply amalgamation.patch

This does not require installing astyle yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

to_msgpack() silently emits corrupt output (or reads out of bounds) above the documented 4294967295 size limit

2 participants