Skip to content

AVRO-4228: [c++] Fix BinaryDecoder::arrayNext() to handle negative block counts (branch-1.12 backport) - #3950

Open
iemejia wants to merge 1 commit into
apache:branch-1.12from
iemejia:AVRO-4228-cpp-backport-1.12
Open

AVRO-4228: [c++] Fix BinaryDecoder::arrayNext() to handle negative block counts (branch-1.12 backport)#3950
iemejia wants to merge 1 commit into
apache:branch-1.12from
iemejia:AVRO-4228-cpp-backport-1.12

Conversation

@iemejia

@iemejia iemejia commented Aug 22, 2026

Copy link
Copy Markdown
Member

Backport of #3646 (commit 3508f0ec8d) to branch-1.12.

BinaryDecoder::arrayNext() called doDecodeLong() directly instead of doDecodeItemCount(), so it mishandled negative array/map block counts. Per the Avro spec a negative block count means the absolute value is the item count, followed by a long block byte-size; doDecodeItemCount() handles that (and avoids UB when negating INT64_MIN), and is already used by arrayStart()/mapStart().

This is the reason AVRO-4228 was reopened — the fix landed on main but was not cherry-picked to branch-1.12. Cherry-pick applies cleanly; C++ CodecTests (incl. the added negative-block-count test) pass.

JIRA: https://issues.apache.org/jira/browse/AVRO-4228

…ock counts (apache#3646)

* AVRO-4228: Fix BinaryDecoder::arrayNext() to handle negative block counts

* AVRO-4228: Add test for arrayNext() with negative block counts

* AVRO-4228: Move negative block count to second block in test

* AVRO-4228: Avoid undefined behavior when negating INT64_MIN in doDecodeItemCount

---------

Co-authored-by: Gabriel Feyer <gabriel.feyer@indexexchange.com>
(cherry picked from commit 3508f0e)
@github-actions github-actions Bot added the C++ Pull Requests for C++ binding label Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C++ Pull Requests for C++ binding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants