MINOR: [c++] validate union and enum index in the resolving reader#3893
Open
arib06 wants to merge 1 commit into
Open
MINOR: [c++] validate union and enum index in the resolving reader#3893arib06 wants to merge 1 commit into
arib06 wants to merge 1 commit into
Conversation
The branch index and enum ordinal come straight off the wire and were used to index the resolver vectors unchecked; the enum bound was an assert that Release builds drop. Reject out-of-range values instead.
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
ResolverSchema/ResolvingReaderis the path used to read a datum written with an older writer schema into anavrogencpp-generated struct, so both the writer schema and the bytes come from the data file. The union branch index and the enum ordinal are plain zigzag varints in that datum, andReaderisReaderImpl<NullValidator>, so nothing upstream range-checks them beforeResolver.ccuses them to indexresolvers_,choiceMapping_andmapping_. Two bytes (90 4e) select branch 5000 of a two-branch union; the out-of-boundsResolver*that comes back is then virtual-dispatched. The enum site did have a bound, but as anassert, which Release builds drop with-DNDEBUG, and there the out-of-bounds heap word is also copied into the caller's deserialized object. I hit this while feeding malformed datums through the resolving reader under ASan, which reports a heap-buffer-overflow read of 8 bytes atResolver.cc:332andResolver.cc:312. The check now lives next to each index, next to where the value is read, so all four resolver variants reject the branch instead of trusting it.Verifying this change
This change added tests and can be verified as follows:
TestBadStuff::testOutOfRangeUnionIndexandTestBadStuff::testOutOfRangeEnumIndexintest/unittest.cc, which drive a resolving reader with an out-of-range branch index and ordinal and expectavro::Exception. Without the patch./build/unittestdies with a memory access violation in the first of them../build.sh testand aCMAKE_BUILD_TYPE=Releasebuild both pass.Documentation