diff --git a/src/draco/compression/attributes/kd_tree_attributes_decoder.cc b/src/draco/compression/attributes/kd_tree_attributes_decoder.cc index 51c41cf7a..de37425f6 100644 --- a/src/draco/compression/attributes/kd_tree_attributes_decoder.cc +++ b/src/draco/compression/attributes/kd_tree_attributes_decoder.cc @@ -259,7 +259,7 @@ bool KdTreeAttributesDecoder::DecodePortableAttributes( template bool KdTreeAttributesDecoder::DecodePoints(int total_dimensionality, - int num_expected_points, + uint32_t num_expected_points, DecoderBuffer *in_buffer, OutIteratorT *out_iterator) { DynamicIntegerPointsKdTreeDecoder decoder(total_dimensionality); @@ -399,54 +399,55 @@ bool KdTreeAttributesDecoder::DecodeDataNeededByPortableTransforms( attr->SetIdentityMapping(); } - PointAttributeVectorOutputIterator out_it(atts); + using OutIt = PointAttributeVectorOutputIterator; + OutIt out_it(atts); switch (compression_level) { case 0: { - DynamicIntegerPointsKdTreeDecoder<0> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) { + if (!DecodePoints<0, OutIt>(total_dimensionality, num_points, in_buffer, + &out_it)) { return false; } break; } case 1: { - DynamicIntegerPointsKdTreeDecoder<1> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) { + if (!DecodePoints<1, OutIt>(total_dimensionality, num_points, in_buffer, + &out_it)) { return false; } break; } case 2: { - DynamicIntegerPointsKdTreeDecoder<2> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) { + if (!DecodePoints<2, OutIt>(total_dimensionality, num_points, in_buffer, + &out_it)) { return false; } break; } case 3: { - DynamicIntegerPointsKdTreeDecoder<3> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) { + if (!DecodePoints<3, OutIt>(total_dimensionality, num_points, in_buffer, + &out_it)) { return false; } break; } case 4: { - DynamicIntegerPointsKdTreeDecoder<4> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) { + if (!DecodePoints<4, OutIt>(total_dimensionality, num_points, in_buffer, + &out_it)) { return false; } break; } case 5: { - DynamicIntegerPointsKdTreeDecoder<5> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) { + if (!DecodePoints<5, OutIt>(total_dimensionality, num_points, in_buffer, + &out_it)) { return false; } break; } case 6: { - DynamicIntegerPointsKdTreeDecoder<6> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) { + if (!DecodePoints<6, OutIt>(total_dimensionality, num_points, in_buffer, + &out_it)) { return false; } break; diff --git a/src/draco/compression/attributes/kd_tree_attributes_decoder.h b/src/draco/compression/attributes/kd_tree_attributes_decoder.h index 4af367a1a..344ffd429 100644 --- a/src/draco/compression/attributes/kd_tree_attributes_decoder.h +++ b/src/draco/compression/attributes/kd_tree_attributes_decoder.h @@ -32,7 +32,7 @@ class KdTreeAttributesDecoder : public AttributesDecoder { private: template - bool DecodePoints(int total_dimensionality, int num_expected_points, + bool DecodePoints(int total_dimensionality, uint32_t num_expected_points, DecoderBuffer *in_buffer, OutIteratorT *out_iterator); template diff --git a/src/draco/compression/point_cloud/point_cloud_kd_tree_encoding_test.cc b/src/draco/compression/point_cloud/point_cloud_kd_tree_encoding_test.cc index 7a7b597f2..1ca02d58e 100644 --- a/src/draco/compression/point_cloud/point_cloud_kd_tree_encoding_test.cc +++ b/src/draco/compression/point_cloud/point_cloud_kd_tree_encoding_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // +#include "draco/compression/decode.h" #include "draco/compression/point_cloud/point_cloud_kd_tree_decoder.h" #include "draco/compression/point_cloud/point_cloud_kd_tree_encoder.h" #include "draco/core/draco_test_base.h" @@ -120,6 +121,25 @@ TEST_F(PointCloudKdTreeEncodingTest, TestIntKdTreeEncoding) { TestKdTreeEncoding(*pc); } +TEST_F(PointCloudKdTreeEncodingTest, TestRejectMismatchedLegacyPointCount) { + const uint8_t data[] = { + 0x44, 0x52, 0x41, 0x43, 0x4f, 0x02, 0x00, 0x00, 0x01, 0x01, 0x13, 0x00, + 0x8d, 0x01, 0x0d, 0x01, 0x02, 0x01, 0x04, 0x03, 0x00, 0x00, 0x00, 0x01, + 0x01, 0x00, 0x07, 0x01, 0x02, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x32, 0x32, 0xff, 0xe7, 0xff, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x68, 0x24, 0x00, 0x0e, 0x18, 0x3a, 0x08, 0x00, 0x00, 0x00, 0x67, 0x30, + 0x13, 0xfe, 0x00, 0x0b, 0x00, 0x21, 0x08, 0x00, 0x00, 0x00, 0xe4, 0xd3, + 0x00, 0xff, 0x80, 0xba, 0xff, 0x01, 0x14, 0x00, 0x00, 0x00, 0x00, 0xff, + 0xe7, 0xff, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x24, 0x00, 0x20, + 0x00, 0x0e, 0x18, 0xff, 0xff, 0xff}; + + DecoderBuffer buffer; + buffer.Init(reinterpret_cast(data), sizeof(data)); + Decoder decoder; + decoder.SetSkipAttributeTransform(GeometryAttribute::POSITION); + EXPECT_FALSE(decoder.DecodePointCloudFromBuffer(&buffer).ok()); +} + // test higher dimensions with more attributes TEST_F(PointCloudKdTreeEncodingTest, TestIntKdTreeEncodingHigherDimension) { constexpr int num_points = 120;