From 4f640c5bd6724134b3c94ecc2cf7458e9402a697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 3 Mar 2022 11:08:23 +0100 Subject: [PATCH 1/5] add test failing from issue 6374 --- .../Stream_support/data/binary-issue-6374.stl | Bin 0 -> 684 bytes Stream_support/test/Stream_support/test_STL.cpp | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 Stream_support/test/Stream_support/data/binary-issue-6374.stl 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 0000000000000000000000000000000000000000..82709ac4a42c56f55ddc7188c3bdf9793a3ae723 GIT binary patch literal 684 zcmb`F!4bkR3UdvGTr Y7V^M+f`E=r&>8v{IiuQdMtFeu0e=0BWdHyG literal 0 HcmV?d00001 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; } From 733c8de28b02da67acfe0111df50e7c6ff7121fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 3 Mar 2022 11:14:50 +0100 Subject: [PATCH 2/5] do not try to read after the 80 char for the header Since the next "word" to be read is a INT32 in binary mode, the char read from it does not mean anything --- Stream_support/include/CGAL/IO/STL.h | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Stream_support/include/CGAL/IO/STL.h b/Stream_support/include/CGAL/IO/STL.h index e2f0ac84df9..1d4673e3720 100644 --- a/Stream_support/include/CGAL/IO/STL.h +++ b/Stream_support/include/CGAL/IO/STL.h @@ -105,20 +105,12 @@ bool read_STL(std::istream& is, break; } ++pos; + if (pos==80) break; // we stop when we reached the header limit } 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" From fef50179e03ffeb1ea458428c77019630db289a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 3 Mar 2022 16:05:24 +0100 Subject: [PATCH 3/5] allow ASCII files with many spaces on the first lines --- Stream_support/include/CGAL/IO/STL.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/Stream_support/include/CGAL/IO/STL.h b/Stream_support/include/CGAL/IO/STL.h index 1d4673e3720..7632aad2736 100644 --- a/Stream_support/include/CGAL/IO/STL.h +++ b/Stream_support/include/CGAL/IO/STL.h @@ -105,14 +105,11 @@ bool read_STL(std::istream& is, break; } ++pos; - if (pos==80) break; // we stop when we reached the header limit } if(!is.good()) // reached the end return true; - // 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; From eb505ae8b88dfcd95190a620e0d88e2785dd888a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 4 Mar 2022 06:04:39 +0100 Subject: [PATCH 4/5] remove unused variable --- Stream_support/include/CGAL/IO/STL.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/Stream_support/include/CGAL/IO/STL.h b/Stream_support/include/CGAL/IO/STL.h index 7632aad2736..fee61542fe6 100644 --- a/Stream_support/include/CGAL/IO/STL.h +++ b/Stream_support/include/CGAL/IO/STL.h @@ -93,7 +93,6 @@ bool read_STL(std::istream& is, return false; } - int pos = 0; // Ignore all initial whitespace unsigned char c; @@ -104,7 +103,6 @@ bool read_STL(std::istream& is, is.unget(); // move back to the first interesting char break; } - ++pos; } if(!is.good()) // reached the end @@ -122,7 +120,6 @@ bool read_STL(std::istream& is, is.read(reinterpret_cast(&word[5]), sizeof(c))) { s = std::string(word, 5); - pos += 5; } else { From 72853c00da927e99b5ba3bcddffaaaacea3e95ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 4 Mar 2022 15:29:34 +0100 Subject: [PATCH 5/5] remove unused variable --- Stream_support/include/CGAL/IO/STL.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Stream_support/include/CGAL/IO/STL.h b/Stream_support/include/CGAL/IO/STL.h index fee61542fe6..a3d10b74435 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()) {