Skip to content

Add missing bounds check in RAnsDecoder::read_init#1192

Open
TristanInSec wants to merge 1 commit intogoogle:mainfrom
TristanInSec:fix-rans-read-init-bounds
Open

Add missing bounds check in RAnsDecoder::read_init#1192
TristanInSec wants to merge 1 commit intogoogle:mainfrom
TristanInSec:fix-rans-read-init-bounds

Conversation

@TristanInSec
Copy link
Copy Markdown

Summary

  • Add offset < 4 guard to the x == 3 branch in RAnsDecoder::read_init()
  • The other branches (x == 1, x == 2) already validate their respective minimum offsets before reading
  • Prevents reading before the start of the buffer when offset is less than 4

Test plan

  • Verified the fix rejects small offsets in the x==3 path
  • Confirmed existing branches (x==0, x==1, x==2) are unchanged
  • Matches the guard pattern used by the legacy ans_read_init C function

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 17, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

The x==3 branch reads 4 bytes via mem_get_le32 but does not
validate that offset >= 4 before computing buf + offset - 4.
The other branches (x==1, x==2) already have their respective
guards. Add the missing check to return an error when the
buffer is too small.
@TristanInSec TristanInSec force-pushed the fix-rans-read-init-bounds branch from bbe8d5e to da3003f Compare April 17, 2026 16:22
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