Merge branch 'test_ply_reader' into 'master'
Prevent endless loop in PLY reader when unknown property types are read. See merge request OpenMesh/OpenMesh!178
This commit is contained in:
@@ -1240,13 +1240,15 @@ bool _PLYReader_::can_u_read(std::istream& _is) const {
|
||||
|
||||
if (listIndexType == "uint8") {
|
||||
indexType = ValueTypeUINT8;
|
||||
} else if (listIndexType == "uint16") {
|
||||
indexType = ValueTypeUINT16;
|
||||
} else if (listIndexType == "uchar") {
|
||||
indexType = ValueTypeUCHAR;
|
||||
} else if (listIndexType == "int") {
|
||||
indexType = ValueTypeINT;
|
||||
} else {
|
||||
omerr() << "Unsupported Index type for property list: " << listIndexType << std::endl;
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
entryType = get_property_type(listEntryType, listEntryType);
|
||||
|
||||
@@ -728,4 +728,58 @@ TEST_F(OpenMeshReadWritePLY, LoadSimpleBinaryPLYWithExtraElements) {
|
||||
EXPECT_EQ(12u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Ignore a file that does not contain vertices and faces
|
||||
*/
|
||||
TEST_F(OpenMeshReadWritePLY, IgnoreNonMeshPlyFile) {
|
||||
|
||||
mesh_.clear();
|
||||
|
||||
std::stringstream data;
|
||||
data << "ply" << "\n";
|
||||
data << "format binary_little_endian 1.0" << "\n";
|
||||
data << "comment Image data" << "\n";
|
||||
data << "element image 0" << "\n";
|
||||
data << "property list uint16 uint16 row" << "\n";
|
||||
data << "end_header" << "\n";
|
||||
|
||||
OpenMesh::IO::Options options = OpenMesh::IO::Options::Binary;
|
||||
|
||||
bool ok = OpenMesh::IO::read_mesh(mesh_, data, ".ply", options);
|
||||
|
||||
EXPECT_TRUE(ok) << "This empty file should be readable without an error!";
|
||||
|
||||
EXPECT_EQ(0u, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
|
||||
EXPECT_EQ(0u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
|
||||
EXPECT_EQ(0u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Ignore a file that does not contain vertices and faces
|
||||
*/
|
||||
TEST_F(OpenMeshReadWritePLY, FailOnUnknownPropertyTypeForLists) {
|
||||
|
||||
mesh_.clear();
|
||||
|
||||
std::stringstream data;
|
||||
data << "ply" << "\n";
|
||||
data << "format binary_little_endian 1.0" << "\n";
|
||||
data << "comment Image data" << "\n";
|
||||
data << "element image 0" << "\n";
|
||||
data << "property list blibb blubb row" << "\n";
|
||||
data << "end_header" << "\n";
|
||||
|
||||
OpenMesh::IO::Options options = OpenMesh::IO::Options::Binary;
|
||||
|
||||
bool ok = OpenMesh::IO::read_mesh(mesh_, data, ".ply", options);
|
||||
|
||||
EXPECT_FALSE(ok) << "This file should fail to read!";
|
||||
|
||||
EXPECT_EQ(0u, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
|
||||
EXPECT_EQ(0u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
|
||||
EXPECT_EQ(0u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user