mesh: validate num_faces against buffer capacity in Edgebreaker (fixes #1169) - #1242
Open
jdymitarai wants to merge 1 commit into
Open
jdymitarai wants to merge 1 commit into
jdymitarai wants to merge 1 commit into
Conversation
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.
Root Cause
In
MeshEdgebreakerDecoderImpl::DecodeConnectivity()(src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.cc),num_facesis decoded from untrusted input buffer and validated only againststd::numeric_limits<CornerIndex::ValueType>::max() / 3. However, the decoder never validates thatnum_facescan realistically fit within the remaining buffer size. When a crafted input supplies a largenum_faces(such as0x33333333in the 61-byte PoC of #1169), subsequent allocations inprocessed_corner_ids_.reserve(num_faces)andcorner_table_->Reset(num_faces, ...)attempt multi-gigabyte memory allocations, triggering uncontrolled memory allocation (CWE-789) and DoS crashes.Fix
Similar to the bounds checks in
MeshSequentialDecoder::DecodeConnectivity()andAttributesDecoder::DecodeAttributesDecoderData(), validatenum_facesagainst the remaining buffer capacity before performing memory allocations or graph connectivity setup. Ifnum_faces > 0and the remaining buffer size is non-positive or insufficient to hold the minimum bits required for that many faces, reject decoding by returningfalse.Verification
Added a regression test
MeshEdgebreakerEncodingTest.RejectMalformedOversizedFacesinsrc/draco/compression/mesh/mesh_edgebreaker_encoding_test.ccusing the 61-byte Base64 PoC from issue #1169. Verified that the malformed input is safely rejected with an error status without triggering excessive memory allocation or crashes.