Bound col_starts indices in TrackingData motion-vector decoding (heap OOB read) - #6311
Open
evilgensec wants to merge 1 commit into
Open
Bound col_starts indices in TrackingData motion-vector decoding (heap OOB read)#6311evilgensec wants to merge 1 commit into
evilgensec wants to merge 1 commit into
Conversation
MotionVectorFrameFromTrackingData and FeatureAndDescriptorFromTrackingData walk a compressed-sparse-column structure built from independent repeated fields of TrackingData (col_starts, row_indices, vector_data, track_id, feature_descriptors). The col_starts values are used as loop bounds and as indices into the other arrays with no check that they are within those arrays' sizes. A TrackingData whose col_starts exceed the dependent arrays drives the index past the end of the protobuf RepeatedField, a heap out-of-bounds read (RepeatedField::Get is unchecked under NDEBUG with the default bounds-check mode). This is reachable from deserialized TrackingData (e.g. BoxTracker cache chunks and the BoxTrackerCalculator TRACKING input). Reject indices that fall outside the dependent repeated fields before dereferencing.
Author
|
Checking in on this. Anything I can do to help get it reviewed? |
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.
Problem
MotionVectorFrameFromTrackingData()(and the siblingFeatureAndDescriptorFromTrackingData()) inmediapipe/util/tracking/tracking.ccdecodea compressed-sparse-column layout from a
TrackingDataproto:col_starts,row_indices,vector_data,track_id(andfeature_descriptors) areindependent
repeatedfields; nothing constrainscol_starts(c+1)to the sizes of theothers. A
TrackingDatawhosecol_startsvalues exceed the dependent arrays drivesr(and
2*r) past the end of eachRepeatedField.RepeatedField::Get(int)is boundschecked only when the bounds-check mode is
kAbort; with the default mode it is anunchecked
elements()[index](theABSL_DCHECKis a no-op underNDEBUG), so this is aheap out-of-bounds read in opt builds. Out-of-bounds heap contents are emitted as box
coordinates; large values crash.
This is reachable from deserialized
TrackingData:BoxTracker::ReadChunkFromCacheparses
chunk_*cache files (box_tracker.cc) and feeds them here, andBoxTrackerCalculatoracceptsTrackingDataon itsTRACKINGinput stream. Thebinary-decode path (
FlowPackager::DecodeTrackingData) has a consistency check(
ABSL_CHECK_EQ(num_vectors, col_starts.back())), but these direct-proto paths do not.Fix
Before dereferencing, reject an index
rthat falls outside the dependent repeatedfields. Because
rincreases monotonically within the inner loop, breaking on the firstout-of-range index is sufficient and changes nothing for well-formed input. The same guard
is added to
FeatureAndDescriptorFromTrackingData.