Skip to content

prevent out-of-bounds access in ForAllFields#9000

Open
metsw24-max wants to merge 2 commits intogoogle:masterfrom
metsw24-max:reflection-forallfields-oob
Open

prevent out-of-bounds access in ForAllFields#9000
metsw24-max wants to merge 2 commits intogoogle:masterfrom
metsw24-max:reflection-forallfields-oob

Conversation

@metsw24-max
Copy link
Copy Markdown

Fixes an out-of-bounds access in ForAllFields caused by using field->id() as an unchecked index into an internal mapping. Malformed or adversarial schemas can provide out-of-range field IDs, leading to heap-buffer-overflow reads and writes during field traversal. This change adds a bounds check, uses a sentinel-based mapping to avoid invalid entries, and corrects reverse iteration indexing, eliminating both memory safety issues and duplicate traversal artifacts while preserving behavior for valid schemas. The issue was reproduced with AddressSanitizer and is now resolved

@github-actions github-actions bot added c++ codegen Involving generating code from schema labels Mar 28, 2026
@metsw24-max
Copy link
Copy Markdown
Author

@jtdavis777
added early return for empty fields() to avoid unnecessary allocation.
Core logic unchanged
OOB safeguards and traversal behavior remain intact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ codegen Involving generating code from schema

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants