diff --git a/Stream_support/include/CGAL/IO/STL.h b/Stream_support/include/CGAL/IO/STL.h index 530dd5035f9..3854efa1f1d 100644 --- a/Stream_support/include/CGAL/IO/STL.h +++ b/Stream_support/include/CGAL/IO/STL.h @@ -84,7 +84,6 @@ bool read_STL(std::istream& is, ) { const bool verbose = parameters::choose_parameter(parameters::get_parameter(np, internal_np::verbose), false); - const bool binary = CGAL::parameters::choose_parameter(CGAL::parameters::get_parameter(np, internal_np::use_binary_mode), true); if(!is.good()) { @@ -93,7 +92,6 @@ bool read_STL(std::istream& is, return false; } - int pos = 0; // Ignore all initial whitespace unsigned char c; @@ -104,23 +102,11 @@ bool read_STL(std::istream& is, is.unget(); // move back to the first interesting char break; } - ++pos; } if(!is.good()) // reached the end return true; - // If we have gone beyond 80 characters and have not read anything yet, - // then this must be an ASCII file. - if(pos > 80) - { - if(binary) - return false; - return internal::parse_ASCII_STL(is, points, facets, verbose); - } - - // We are within the first 80 characters, both ASCII and binary are possible - // Read the 5 first characters to check if the first word is "solid" std::string s; @@ -133,7 +119,6 @@ bool read_STL(std::istream& is, is.read(reinterpret_cast(&word[5]), sizeof(c))) { s = std::string(word, 5); - pos += 5; } else { diff --git a/Stream_support/test/Stream_support/data/binary-issue-6374.stl b/Stream_support/test/Stream_support/data/binary-issue-6374.stl new file mode 100644 index 00000000000..82709ac4a42 Binary files /dev/null and b/Stream_support/test/Stream_support/data/binary-issue-6374.stl differ diff --git a/Stream_support/test/Stream_support/test_STL.cpp b/Stream_support/test/Stream_support/test_STL.cpp index 9fd3dffe5f0..705ea72f7e5 100644 --- a/Stream_support/test/Stream_support/test_STL.cpp +++ b/Stream_support/test/Stream_support/test_STL.cpp @@ -79,8 +79,8 @@ int main(int argc, char** argv) assert(ok); std::cout << points.size() << " points and " << polygons.size() << " polygons" << std::endl; - if(argc == 0) - assert(points.size() == 434 && polygons.size() == 864); + if(argc == 1) + assert(points.size() == 4 && polygons.size() == 4); points.clear(); polygons.clear(); @@ -129,6 +129,16 @@ int main(int argc, char** argv) further_tests(); + // issue 6374 + if(argc == 1) + { + points.clear(); + polygons.clear(); + bool ok = CGAL::IO::read_STL("data/binary-issue-6374.stl", points, polygons, CGAL::parameters::verbose(true)); + assert(ok); + assert(points.size()==8 && polygons.size()==12); + } + std::cout << "Done!" << std::endl; return EXIT_SUCCESS; }