Skip to content

fix(java): advance readerIndex in continueReadBinarySize - #4133

Merged
chaokunyang merged 2 commits into
apache:mainfrom
Hkwaynewing:reader-bug
Oct 7, 2026
Merged

chaokunyang merged 2 commits into
apache:mainfrom
Hkwaynewing:reader-bug

Conversation

@Hkwaynewing

Copy link
Copy Markdown
Contributor

Why?

The 3/4-byte varint length-prefix fast path of readBinarySize() delegates to continueReadBinarySize(), which decoded the size but never assigned readerIndex, unlike the <=2-byte path. readBytesAndSize() (and readStringAndSize / *WithSize primitive readers) then copied the body from the stale index, i.e. starting at the first prefix byte: payloads with big enough length came back shifted by the prefix width, silently corrupted, or failed downstream with "reserved header bitmap flags" errors.

What does this PR do?

Fix both the base and the java25 MemoryBuffer by assigning readerIndex = readIdx in continueReadBinarySize, matching continueReadVarUInt32. Add a regression test covering 3-byte and 4-byte prefixes plus a trailing read to verify index alignment.

The Android path (MemoryOps.readBinarySize -> readVarUInt32) already advances readerIndex correctly and needed no change.

Related issues

No related issue found

The 3/4-byte varint length-prefix fast path of readBinarySize()
delegates to continueReadBinarySize(), which decoded the size but
never assigned readerIndex, unlike the <=2-byte path. readBytesAndSize()
(and readStringAndSize / *WithSize primitive readers) then copied the
body from the stale index, i.e. starting at the first prefix byte:
payloads with big enough length came back shifted by the prefix width,
silently corrupted, or failed downstream with "reserved header bitmap
flags" errors.

Fix both the base and the java25 MemoryBuffer by assigning
readerIndex = readIdx in continueReadBinarySize, matching
continueReadVarUInt32. Add a regression test covering 3-byte and
4-byte prefixes plus a trailing read to verify index alignment.

The Android path (MemoryOps.readBinarySize -> readVarUInt32) already
advances readerIndex correctly and needed no change.

@chaokunyang chaokunyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@chaokunyang
chaokunyang merged commit bb2c1c9 into apache:main Oct 7, 2026
135 of 136 checks passed
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