mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-16 10:08:36 +03:00
0027622: Data Exchange - STL file having less than 4 triangles cannot be read
Drop minimum file size check from RWStl::ReadBinary(). Test case for issue #27622
This commit is contained in:
parent
284c923864
commit
a47d34efa9
@ -20,6 +20,8 @@
|
|||||||
#include <gp.hxx>
|
#include <gp.hxx>
|
||||||
#include <gp_Vec.hxx>
|
#include <gp_Vec.hxx>
|
||||||
#include <gp_XYZ.hxx>
|
#include <gp_XYZ.hxx>
|
||||||
|
#include <Message.hxx>
|
||||||
|
#include <Message_Messenger.hxx>
|
||||||
#include <Message_ProgressIndicator.hxx>
|
#include <Message_ProgressIndicator.hxx>
|
||||||
#include <Message_ProgressSentry.hxx>
|
#include <Message_ProgressSentry.hxx>
|
||||||
#include <OSD.hxx>
|
#include <OSD.hxx>
|
||||||
@ -66,7 +68,6 @@ static Standard_Integer AddVertex(Handle(StlMesh_Mesh)& mesh,
|
|||||||
// constants
|
// constants
|
||||||
static const size_t HEADER_SIZE = 84;
|
static const size_t HEADER_SIZE = 84;
|
||||||
static const size_t SIZEOF_STL_FACET = 50;
|
static const size_t SIZEOF_STL_FACET = 50;
|
||||||
static const size_t STL_MIN_FILE_SIZE = 284;
|
|
||||||
static const size_t ASCII_LINES_PER_FACET = 7;
|
static const size_t ASCII_LINES_PER_FACET = 7;
|
||||||
|
|
||||||
static const int IND_THRESHOLD = 1000; // increment the indicator every 1k triangles
|
static const int IND_THRESHOLD = 1000; // increment the indicator every 1k triangles
|
||||||
@ -356,7 +357,6 @@ Handle(StlMesh_Mesh) RWStl::ReadFile (const OSD_Path& thePath,
|
|||||||
Handle(StlMesh_Mesh) RWStl::ReadBinary (const OSD_Path& thePath,
|
Handle(StlMesh_Mesh) RWStl::ReadBinary (const OSD_Path& thePath,
|
||||||
const Handle(Message_ProgressIndicator)& /*theProgInd*/)
|
const Handle(Message_ProgressIndicator)& /*theProgInd*/)
|
||||||
{
|
{
|
||||||
Standard_Integer NBFACET;
|
|
||||||
Standard_Integer ifacet;
|
Standard_Integer ifacet;
|
||||||
Standard_Real fx,fy,fz,fx1,fy1,fz1,fx2,fy2,fz2,fx3,fy3,fz3;
|
Standard_Real fx,fy,fz,fx1,fy1,fz1,fx2,fy2,fz2,fx3,fy3,fz3;
|
||||||
Standard_Integer i1,i2,i3,lread;
|
Standard_Integer i1,i2,i3,lread;
|
||||||
@ -374,14 +374,34 @@ Handle(StlMesh_Mesh) RWStl::ReadBinary (const OSD_Path& thePath,
|
|||||||
// compute file size
|
// compute file size
|
||||||
Standard_Size filesize = theFile.Size();
|
Standard_Size filesize = theFile.Size();
|
||||||
|
|
||||||
if ( (filesize - HEADER_SIZE) % SIZEOF_STL_FACET !=0
|
// don't trust the number of triangles which is coded in the file sometimes it is wrong
|
||||||
|| (filesize < STL_MIN_FILE_SIZE)) {
|
Standard_Integer NBFACET = (Standard_Integer)((filesize - HEADER_SIZE) / SIZEOF_STL_FACET);
|
||||||
|
if (NBFACET < 1)
|
||||||
|
{
|
||||||
Standard_NoMoreObject::Raise("RWStl::ReadBinary (wrong file size)");
|
Standard_NoMoreObject::Raise("RWStl::ReadBinary (wrong file size)");
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't trust the number of triangles which is coded in the file
|
theFile.Seek (80, OSD_FromBeginning);
|
||||||
// sometimes it is wrong, and with this technique we don't need to swap endians for integer
|
theFile.Read (adr, 4, lread);
|
||||||
NBFACET = (Standard_Integer)((filesize - HEADER_SIZE) / SIZEOF_STL_FACET);
|
Standard_Integer aNbTrisInHeader = (((char* )buftest)[3] << 24) | (((Standard_Byte* )buftest)[2] << 16)
|
||||||
|
| (((Standard_Byte* )buftest)[1] << 8 ) | (((Standard_Byte* )buftest)[0] << 0 );
|
||||||
|
if (NBFACET < aNbTrisInHeader)
|
||||||
|
{
|
||||||
|
Message::DefaultMessenger()->Send (TCollection_AsciiString ("RWStl - Binary STL file defines more triangles (") + aNbTrisInHeader
|
||||||
|
+ ") that can be read (" + NBFACET + ") - probably corrupted file",
|
||||||
|
Message_Warning);
|
||||||
|
}
|
||||||
|
else if (NBFACET > aNbTrisInHeader)
|
||||||
|
{
|
||||||
|
Message::DefaultMessenger()->Send (TCollection_AsciiString ("RWStl - Binary STL file defines less triangles (") + aNbTrisInHeader
|
||||||
|
+ ") that can be read (" + NBFACET + ") - probably corrupted file",
|
||||||
|
Message_Warning);
|
||||||
|
}
|
||||||
|
else if ((filesize - HEADER_SIZE) % SIZEOF_STL_FACET != 0)
|
||||||
|
{
|
||||||
|
Message::DefaultMessenger()->Send (TCollection_AsciiString ("RWStl - Binary STL file has unidentified tail"),
|
||||||
|
Message_Warning);
|
||||||
|
}
|
||||||
|
|
||||||
// skip the header
|
// skip the header
|
||||||
theFile.Seek(HEADER_SIZE,OSD_FromBeginning);
|
theFile.Seek(HEADER_SIZE,OSD_FromBeginning);
|
||||||
|
25
tests/bugs/stlvrml/bug27622
Normal file
25
tests/bugs/stlvrml/bug27622
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
puts "========"
|
||||||
|
puts "OCC27622"
|
||||||
|
puts "========"
|
||||||
|
puts ""
|
||||||
|
########################################################################
|
||||||
|
# Data Exchange - STL file having less than 4 triangles cannot be read
|
||||||
|
########################################################################
|
||||||
|
|
||||||
|
readstl result [locate_data_file bug27622_Design1.stl]
|
||||||
|
|
||||||
|
set nbshapes_expected "
|
||||||
|
Number of shapes in result
|
||||||
|
VERTEX : 4
|
||||||
|
EDGE : 5
|
||||||
|
WIRE : 2
|
||||||
|
FACE : 2
|
||||||
|
SHELL : 1
|
||||||
|
SOLID : 0
|
||||||
|
COMPSOLID : 0
|
||||||
|
COMPOUND : 0
|
||||||
|
SHAPE : 14
|
||||||
|
"
|
||||||
|
checknbshapes result -ref ${nbshapes_expected} -t -m "Result of STL-reading operation"
|
||||||
|
|
||||||
|
checkview -display result -2d -path ${imagedir}/${test_image}.png
|
Loading…
x
Reference in New Issue
Block a user