Skip to content

[c++] bounds-check reader default lookup in schema resolution#3877

Open
arib06 wants to merge 1 commit into
apache:mainfrom
arib06:cpp-resolve-default-bounds
Open

[c++] bounds-check reader default lookup in schema resolution#3877
arib06 wants to merge 1 commit into
apache:mainfrom
arib06:cpp-resolve-default-bounds

Conversation

@arib06

@arib06 arib06 commented Jul 17, 2026

Copy link
Copy Markdown

What is the purpose of the change

NodeRecord::defaultValueAt returns fieldsDefaultValues_[index] with no bounds check. A record reader schema constructed through the public programmatic API (RecordSchema::addField) never populates fieldsDefaultValues_, so that vector stays empty while the record gains leaves. During schema resolution, when a data file's writer schema omits a field that the reader schema declares, ResolvingGrammarGenerator::resolveRecords calls reader->defaultValueAt(ri) to fetch the reader field's default and reads past the empty vector. The out-of-bounds GenericDatum is then dereferenced by getAvroBinary / GenericWriter::write (GenericDatum::isUnion), which is an out-of-bounds read that crashes. Because the writer schema is attacker-controlled bytes inside the data file header, opening such a file with a programmatically-built reader schema is enough to trigger it. I hit it while reading a corpus file whose writer had dropped a field. The base Node::defaultValueAt already throws Exception("No default value at") for this case, and the sibling customAttributesAt already guards its index the same way, so this brings defaultValueAt in line with both. A missing reader default now surfaces as a normal resolution error instead of a memory fault.

Verifying this change

This change added tests and can be verified as follows:

  • Added a schema test that builds a reader record via RecordSchema::addField with a field absent from the writer schema and asserts that resolvingDecoder throws Exception. It crashes (SEGV, confirmed under ASan) on the current code and passes with the fix.

Documentation

  • Does this pull request introduce a new feature? no

@github-actions github-actions Bot added the C++ Pull Requests for C++ binding label Jul 17, 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.

1 participant