Skip to content

integer overflow in size-prefixed verifier bounds check#9043

Open
jmestwa-coder wants to merge 1 commit intogoogle:masterfrom
jmestwa-coder:verifier-size-prefix-overflow
Open

integer overflow in size-prefixed verifier bounds check#9043
jmestwa-coder wants to merge 1 commit intogoogle:masterfrom
jmestwa-coder:verifier-size-prefix-overflow

Conversation

@jmestwa-coder
Copy link
Copy Markdown

Summary

Fixes an integer overflow risk in the size-prefixed verifier bounds check that could allow malformed buffers to bypass validation.

Problem

The previous check:

ReadScalar(buf_) + sizeof(SizeT) <= size_

performs unsigned arithmetic that can overflow for crafted large prefix values.This wraparound may cause invalid size-prefixed buffers to incorrectly pass verification.

Fix

Replaces the overflow-prone addition with a safe comparison against the remaining buffer size:

prefixed_size <= (size_ - sizeof(SizeT))

  • Preserves original validation logic

  • Eliminates overflow possibility

  • Ensures fail-closed behaviour for malformed inputs

Test

Added a targeted regression case in offset64_test.cpp:

  • Tampered buffer with maximum prefix value

  • Verifies that malformed input is correctly rejected

  • Uses assert = false locally to avoid aborts in debug verification builds

Impact

  • No change to valid input behavior

  • No API or design changes

  • Affects only malformed/overflow cases

  • Minimal, two-file patch

Validation

  • Built successfully with CMake

  • All tests passed (flattests, flattests_cpp17)

  • Verified under strict compiler flags and assertion-enabled mode

  • No new warnings or platform-specific issues

@jmestwa-coder jmestwa-coder force-pushed the verifier-size-prefix-overflow branch from 79dafe3 to 68e7847 Compare April 24, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant