[io] Fix out-of-bounds read/write when parsing OBJ face indices#6448
Open
jamestiotio wants to merge 1 commit into
Open
[io] Fix out-of-bounds read/write when parsing OBJ face indices#6448jamestiotio wants to merge 1 commit into
jamestiotio wants to merge 1 commit into
Conversation
The OBJ reader used the vertex, normal and texture-coordinate indices
taken verbatim from a face ("f") line to index fixed-size vectors with
no bounds checking, most importantly `normal_mapping[v] += normals[n]`.
These indices are fully controlled by the input file, so a crafted face
such as `f 999999//1` turned that line into a read-modify-write of an
Eigen::Vector3f at an arbitrary heap offset, and a short or empty
normal list produced out-of-bounds reads.
Malformed numeric tokens were a second problem: std::stoi throws
std::invalid_argument/std::out_of_range, neither of which the
surrounding `catch (const char*)` handled, so a bad file aborted the
caller with an uncaught exception.
Validate each index against its container's size (and guard the
empty normal case) before use, erroring out cleanly when out of range,
and broaden the handler to std::exception so unparsable indices fail
the read instead of crashing. All three read overloads (PCLPointCloud2,
PolygonMesh, TextureMesh) are fixed. Regression tests cover the
rejected malformed faces and confirm that valid relative (negative)
indices still load.
Signed-off-by: James Raphael Tiovalen <jamestiotio@meta.com>
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.
The OBJ reader used the vertex, normal and texture-coordinate indices taken verbatim from a face ("f") line to index fixed-size vectors with no bounds checking, most importantly
normal_mapping[v] += normals[n]. These indices are fully controlled by the input file, so a crafted face such asf 999999//1turned that line into a read-modify-write of an Eigen::Vector3f at an arbitrary heap offset, and a short or empty normal list produced out-of-bounds reads.Malformed numeric tokens were a second problem: std::stoi throws std::invalid_argument/std::out_of_range, neither of which the surrounding
catch (const char*)handled, so a bad file aborted the caller with an uncaught exception.Validate each index against its container's size (and guard the empty normal case) before use, erroring out cleanly when out of range, and broaden the handler to std::exception so unparsable indices fail the read instead of crashing. All three read overloads (PCLPointCloud2, PolygonMesh, TextureMesh) are fixed. Regression tests cover the rejected malformed faces and confirm that valid relative (negative) indices still load.