fix(flatbuffers): guard GetBufferStartFromRootPointer against OOB read before buffer start#9158
Open
samrigby64 wants to merge 1 commit into
Open
fix(flatbuffers): guard GetBufferStartFromRootPointer against OOB read before buffer start#9158samrigby64 wants to merge 1 commit into
samrigby64 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.
Summary
GetBufferStartFromRootPointerwalks backwards from the root pointer by repeatedly subtractingsizeof(uoffset_t)(up to 9 iterations for 32-byte-aligned buffers) to find the buffer start. It has no check that the walking pointer remains within the buffer allocation. A caller that supplies a root pointer near the beginning of the buffer — or a crafted FlatBuffer with a small or zero vtable offset — will cause the function to read memory before the heap allocation.Root cause
Fix
Add an optional
buf_startparameter (defaults tonullptr— all existing callers are unchanged). When provided, the backward search stops before walking pastbuf_start, breaking out of the loop and falling through to the existingFLATBUFFERS_ASSERT(false)path.The guard fires before the subtraction, so it is safe against pointer underflow. Backward compatibility is preserved — callers that omit
buf_startbehave exactly as before.