From 64c045bdae1d3341155ba85b3943fabff102db7c Mon Sep 17 00:00:00 2001 From: Pavel P Date: Sun, 6 Aug 2017 22:33:38 -0700 Subject: [PATCH 1/2] Fix handling short filenames (less than 4 characters) - fixes https://github.com/google/draco/issues/108 --- src/draco/io/mesh_io.cc | 3 ++- src/draco/io/point_cloud_io.cc | 3 ++- src/draco/tools/draco_decoder.cc | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/draco/io/mesh_io.cc b/src/draco/io/mesh_io.cc index adc66e5..24160ac 100644 --- a/src/draco/io/mesh_io.cc +++ b/src/draco/io/mesh_io.cc @@ -31,7 +31,8 @@ std::unique_ptr ReadMeshFromFile(const std::string &file_name, std::unique_ptr mesh(new Mesh()); // Analyze file extension. const std::string extension = - parser::ToLower(file_name.substr(file_name.size() - 4)); + parser::ToLower(file_name.size() >= 4 ? + file_name.substr(file_name.size() - 4) : file_name); if (extension == ".obj") { // Wavefront OBJ file format. ObjDecoder obj_decoder; diff --git a/src/draco/io/point_cloud_io.cc b/src/draco/io/point_cloud_io.cc index 548da35..d3435a3 100644 --- a/src/draco/io/point_cloud_io.cc +++ b/src/draco/io/point_cloud_io.cc @@ -25,7 +25,8 @@ std::unique_ptr ReadPointCloudFromFile( const std::string &file_name) { std::unique_ptr pc(new PointCloud()); // Analyze file extension. - const std::string extension = file_name.substr(file_name.size() - 4); + const std::string extension = file_name.size() >= 4 ? + file_name.substr(file_name.size() - 4) : file_name; if (extension == ".obj") { // Wavefront OBJ file format. ObjDecoder obj_decoder; diff --git a/src/draco/tools/draco_decoder.cc b/src/draco/tools/draco_decoder.cc index 4f3bac0..512301b 100644 --- a/src/draco/tools/draco_decoder.cc +++ b/src/draco/tools/draco_decoder.cc @@ -134,8 +134,8 @@ int main(int argc, char **argv) { // Save the decoded geometry into a file. // TODO(ostava): Currently only .ply and .obj are supported. - const std::string extension = - options.output.substr(options.output.size() - 4); + const std::string extension = options.output.size() >= 4 ? + options.output.substr(options.output.size() - 4) : options.output; if (extension == ".obj") { draco::ObjEncoder obj_encoder; if (mesh) { From 6a494a8a30e25f97afa967cfd76d96b3aa1e03ef Mon Sep 17 00:00:00 2001 From: Pavel P Date: Sun, 6 Aug 2017 22:36:03 -0700 Subject: [PATCH 2/2] Do not dereference null attribute pointer - avoids crash described in https://github.com/google/draco/issues/171 --- .../mesh_prediction_scheme_tex_coords_portable_decoder.h | 2 +- .../compression/attributes/sequential_attribute_decoder.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h b/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h index e81d853..c323271 100644 --- a/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h +++ b/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h @@ -64,7 +64,7 @@ class MeshPredictionSchemeTexCoordsPortableDecoder } bool SetParentAttribute(const PointAttribute *att) override { - if (att->attribute_type() != GeometryAttribute::POSITION) + if (!att || att->attribute_type() != GeometryAttribute::POSITION) return false; // Invalid attribute type. if (att->num_components() != 3) return false; // Currently works only for 3 component positions. diff --git a/src/draco/compression/attributes/sequential_attribute_decoder.cc b/src/draco/compression/attributes/sequential_attribute_decoder.cc index 1f99af7..fda1e34 100644 --- a/src/draco/compression/attributes/sequential_attribute_decoder.cc +++ b/src/draco/compression/attributes/sequential_attribute_decoder.cc @@ -59,7 +59,7 @@ const PointAttribute *SequentialAttributeDecoder::GetPortableAttribute() { // If needed, copy point to attribute value index mapping from the final // attribute to the portable attribute. if (!attribute_->is_mapping_identity() && - portable_attribute_->is_mapping_identity()) { + portable_attribute_ && portable_attribute_->is_mapping_identity()) { portable_attribute_->SetExplicitMapping(attribute_->indices_map_size()); for (PointIndex i(0); i < attribute_->indices_map_size(); ++i) { portable_attribute_->SetPointMapEntry(i, attribute_->mapped_index(i));