Fix memory safety bugs in PLY, OBJ, and STL decoders#1176
Open
sharadboni wants to merge 2 commits intogoogle:mainfrom
Open
Fix memory safety bugs in PLY, OBJ, and STL decoders#1176sharadboni wants to merge 2 commits intogoogle:mainfrom
sharadboni wants to merge 2 commits intogoogle:mainfrom
Conversation
1. PLY heap-buffer-overflow: Add bounds check on attacker-controlled num_entries in ParseElementData before reading list property data. A crafted PLY file with a large list count can read past the end of the input buffer. 2. OBJ negative-index integer underflow: Validate that the absolute value of negative vertex/texcoord/normal indices does not exceed the number of parsed elements. A crafted OBJ like "f -99999" with few vertices causes num_positions_ + indices[0] to underflow, producing a huge AttributeValueIndex. 3. STL unchecked Decode returns: Check return values of DecoderBuffer::Decode() in the binary STL parser. A truncated STL file causes reads past the buffer without any error.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Author
|
@jzern Could you review this security fix? It addresses a heap-buffer-overflow in the PLY parser, an integer underflow in the OBJ parser, and unchecked return values in the STL decoder. |
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 fixes three memory safety vulnerabilities in Draco's mesh file decoders:
1. PLY heap-buffer-overflow in
ply_reader.ccIn
ParseElementData, thenum_entriesfield of a list property is read from attacker-controlled input and used to computenum_bytes_to_readwithout validating against the remaining buffer size. A crafted PLY file with a large list count causes an out-of-bounds read past the input buffer via theprop.data_.insert(... buffer->data_head() + num_bytes_to_read)call.Fix: Added bounds check that
num_entries >= 0andnum_bytes_to_read <= buffer->remaining_size()before the insert.2. OBJ negative-index integer underflow in
obj_decoder.ccOBJ files support negative vertex indices (e.g.,
f -1 -2 -3) which are relative to the current vertex count. However, there was no validation that|index| <= count. A crafted file likef -99999with only a few vertices causesnum_positions_ + indices[0]to underflow to a huge value, producing an out-of-rangeAttributeValueIndex.Fix: Added validation that
-indices[i] <= num_positions_(and similarly for tex coords and normals) for negative indices, returning an error status on violation.3. STL unchecked Decode return values in
stl_decoder.ccIn
DecodeFromBuffer, all calls tobuffer->Decode()had their boolean return values ignored. A truncated binary STL file causes reads past the end of the buffer without any error reporting.Fix: Check return values of
Decode()andremaining_size()before each buffer operation, returning descriptiveIO_ERRORstatus on truncated input.Test plan
f -99999)