[c++] bounds-check reader default lookup in schema resolution#3877
Open
arib06 wants to merge 1 commit into
Open
[c++] bounds-check reader default lookup in schema resolution#3877arib06 wants to merge 1 commit into
arib06 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
NodeRecord::defaultValueAtreturnsfieldsDefaultValues_[index]with no bounds check. A record reader schema constructed through the public programmatic API (RecordSchema::addField) never populatesfieldsDefaultValues_, 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::resolveRecordscallsreader->defaultValueAt(ri)to fetch the reader field's default and reads past the empty vector. The out-of-boundsGenericDatumis then dereferenced bygetAvroBinary/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 baseNode::defaultValueAtalready throwsException("No default value at")for this case, and the siblingcustomAttributesAtalready guards its index the same way, so this bringsdefaultValueAtin 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:
RecordSchema::addFieldwith a field absent from the writer schema and asserts thatresolvingDecoderthrowsException. It crashes (SEGV, confirmed under ASan) on the current code and passes with the fix.Documentation