Repository navigation
Hardening: add null guards and bounds checks to minireflect, hash functions, and flathash - #9376
Open
anagnorisis2peripeteia wants to merge 1 commit into
Conversation
…ctions, and flathash
This branch has not been deployed
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.
Summary
This PR hardens mini-reflection, hash computation, and the flathash tool against null pointer dereferences and integer underflow hazards:
minireflect.h:InlineSize: Guard againsttype_table == nullptrand validatetype_table->values != nullptrbefore indexing struct sizes.IterateValue: Guard againstvisitor == nullptrandval == nullptr, safely forwarding null/missing values tovisitor->Unknown(val)instead of performing unaligned reads. Guardtype_table == nullptrinET_SEQUENCE.IterateObject: Add early exit whenobj,type_table, orvisitorisnullptr.IterateFlatBuffer: Guard!buffer || !type_table || !callbackand checkroot != nullptrbefore invokingIterateObject.ToStringVisitor: Guardindent_level > 0before decrementing inEndSequence()andEndVector()to prevent unsigned integer underflow. Guardstr == nullptrinString()to avoid dereferencing null string pointers.FlatBufferToString: Return empty string""immediately whenbufferortype_tableisnullptr.hash.h:HashFnv1&HashFnv1a: Guard!inputand return 0 instead of immediately dereferencing*input.FindHashFunction16,FindHashFunction32,FindHashFunction64: Guard!namebefore callingstd::strcmpto prevent segmentation faults on null lookup keys.flathash.cpp:argc > 0 && argv[0]andargv[1]in argument parsing.arg != nullptrbefore inspecting prefix characters and passing to hash functions.Unit Tests:
MiniReflectHashSafetyTest()intests/test.cppverifying behavior with null buffers, null hash names, null strings inToStringVisitor, and underflow resilience.-DFLATBUFFERS_STRICT_MODE=ON,flattests, andflatc_cpp_tests.py.