Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions src/draco/compression/attributes/kd_tree_attributes_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ bool KdTreeAttributesDecoder::DecodePortableAttributes(

template <int level_t, typename OutIteratorT>
bool KdTreeAttributesDecoder::DecodePoints(int total_dimensionality,
int num_expected_points,
uint32_t num_expected_points,
DecoderBuffer *in_buffer,
OutIteratorT *out_iterator) {
DynamicIntegerPointsKdTreeDecoder<level_t> decoder(total_dimensionality);
Expand Down Expand Up @@ -399,54 +399,55 @@ bool KdTreeAttributesDecoder::DecodeDataNeededByPortableTransforms(
attr->SetIdentityMapping();
}

PointAttributeVectorOutputIterator<uint32_t> out_it(atts);
using OutIt = PointAttributeVectorOutputIterator<uint32_t>;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class KdTreeAttributesDecoder : public AttributesDecoder {

private:
template <int level_t, typename OutIteratorT>
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 <typename SignedDataTypeT>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<const char *>(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;
Expand Down