Skip to content

GH-51156: [C++] Raise CapacityError instead of truncating binary values over 2 GiB - #51158

Merged
pitrou merged 1 commit into
apache:mainfrom
ngoldbaum:fix-truncation
Sep 7, 2026
Merged

pitrou merged 1 commit into
apache:mainfrom
ngoldbaum:fix-truncation

Conversation

@ngoldbaum

Copy link
Copy Markdown
Contributor

Rationale for this change

BaseBinaryBuilder::Append(std::string_view), ExtendCurrent(std::string_view) and ChunkedBinaryBuilder::Append(std::string_view) cast the value size to int32_t before validating it, so a value of 2 GiB or more is stored as an empty or truncated value. See #51156.

What changes are included in this PR?

The three overloads validate the 64-bit size before narrowing it, returning the same CapacityError that ValidateOverflow produces for the other paths.

Are these changes tested?

Yes, two LARGE_MEMORY_TEST cases in array_binary_test.cc. They fail without the fix.

Are there any user-facing changes?

BinaryBuilder, StringBuilder and ChunkedBinaryBuilder now return CapacityError for a string_view value of 2 GiB or more instead of storing wrong data.

This PR contains a "Critical Fix". The builders produced incorrect data for such values.

AI disclosure: I used an AI model to think about and iterate on the fix. It also originally identified the bug.

@ngoldbaum
ngoldbaum requested a review from pitrou as a code owner September 3, 2026 20:28
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #51156 has been automatically assigned in GitHub to PR creator.

@andishgar

Copy link
Copy Markdown
Contributor

@ngoldbaum, sorry for the confusion—I made a mistake. I was referring to a different topic.

@pitrou pitrou added backport-candidate Critical Fix Bugfixes for security vulnerabilities, crashes, or invalid data. labels Sep 7, 2026

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1, thanks for the fix @ngoldbaum !

@pitrou
pitrou merged commit f4ee045 into apache:main Sep 7, 2026
88 of 108 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-candidate Component: C++ Critical Fix Bugfixes for security vulnerabilities, crashes, or invalid data.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants