fix(kdtree): guard against zero-dimensional attributes and heap-allocate decoder (fixes #1103) - #1224
Open
jdymitarai wants to merge 1 commit into
Open
Conversation
…ate decoder (fixes google#1103) In KdTreeAttributesDecoder::DecodePortableAttributes() and DecodeDataNeededByPortableTransforms(), when malformed input specifies 0 attributes or 0 components across attributes, total_dimensionality evaluates to 0. A 0-dimensional KdTree causes division by zero in DRACO_INCREMENT_MOD(last_axis, dimension_), out-of-bounds index on empty level/base vectors, and invalid memory dereferences (CWE-476 / CWE-125). Furthermore, allocating DynamicIntegerPointsKdTreeDecoder<level_t> on the stack inside DecodePoints creates heavy stack frame overhead with nested decoder arrays, which can cause stack-buffer-overflows in tight stack environments. This commit: 1. Validates total_dimensionality > 0 in DecodePortableAttributes() and DecodeDataNeededByPortableTransforms(). 2. Validates dimension_ > 0 in DynamicIntegerPointsKdTreeDecoder::DecodePoints(). 3. Dynamically allocates DynamicIntegerPointsKdTreeDecoder on the heap via std::unique_ptr in DecodePoints(). 4. Adds a unit test RejectZeroDimensionalAttributes in point_cloud_kd_tree_encoding_test.cc. Fixes google#1103.
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 of Changes
Fixes #1103 (Crash/SEGV in
draco::DecoderBuffer::Peek/DynamicIntegerPointsKdTreeDecoderdue to unvalidated 0-dimensional attribute decoding).Problem
total_dimensionalityinKdTreeAttributesDecoderevaluates to 0. A 0-dimensional KdTree is invalid (point clouds require at least 1 spatial dimension), and passingdimension_ == 0intoDynamicIntegerPointsKdTreeDecodercauses:DRACO_INCREMENT_MOD(last_axis, dimension_)levels_andbase_stack_vectorsPointAttributeVectorOutputIteratorDynamicIntegerPointsKdTreeDecoder<level_t>on the stack inDecodePoints()creates significant stack bloat across all compression levels (0 through 6), which can trigger stack buffer exhaustion.Fix
total_dimensionality > 0inKdTreeAttributesDecoder::DecodePortableAttributes()andDecodeDataNeededByPortableTransforms().dimension_ > 0inDynamicIntegerPointsKdTreeDecoder::DecodePoints().DynamicIntegerPointsKdTreeDecoderon the heap viastd::unique_ptrinDecodePoints()to minimize stack frame size.RejectZeroDimensionalAttributesinsrc/draco/compression/point_cloud/point_cloud_kd_tree_encoding_test.cc.