Skip to content

Commit

Permalink
{standard} The section ID in a compressed vector header must be 1 (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmaloney authored Oct 24, 2023
1 parent fbeeec4 commit 8d9663e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/SectionHeaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ namespace e57

void CompressedVectorSectionHeader::verify( uint64_t filePhysicalSize )
{
// Verify section ID is 1
// cppcheck-suppress knownConditionTrueFalse; (data is read as a blob, so the const might not
// be valid)
if ( sectionId != COMPRESSED_VECTOR_SECTION )
{
throw E57_EXCEPTION2( ErrorBadCVHeader,
"sectionId=" + toString( static_cast<int>( sectionId ) ) +
" (expected 1)" );
}

// Verify reserved fields are zero. ??? if fileversion==1.0 ???
for ( unsigned i = 0; i < sizeof( reserved1 ); i++ )
{
Expand Down
33 changes: 33 additions & 0 deletions test/src/test_SimpleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,39 @@ TEST( SimpleReaderData, ZeroPointsInvalid )
delete reader;
}

TEST( SimpleReaderData, InvalidCVHeader )
{
e57::Reader *reader = nullptr;

E57_ASSERT_NO_THROW( reader =
new e57::Reader( TestData::Path() + "/self/InvalidCVHeader.e57", {} ) );

ASSERT_TRUE( reader->IsOpen() );
EXPECT_EQ( reader->GetImage2DCount(), 0 );
EXPECT_EQ( reader->GetData3DCount(), 1 );

e57::E57Root fileHeader;
ASSERT_TRUE( reader->GetE57Root( fileHeader ) );

CheckFileHeader( fileHeader );
EXPECT_EQ( fileHeader.guid, "InvalidCVHeader GUID" );

e57::Data3D data3DHeader;
ASSERT_TRUE( reader->ReadData3D( 0, data3DHeader ) );

const uint64_t cNumPoints = data3DHeader.pointCount;

e57::Data3DPointsFloat pointsData( data3DHeader );

E57_ASSERT_THROW( {
auto vectorReader = reader->SetUpData3DPointsData( 0, cNumPoints, pointsData );

vectorReader.close();
} );

delete reader;
}

TEST( SimpleReaderData, BadCRC )
{
E57_ASSERT_THROW( e57::Reader( TestData::Path() + "/self/bad-crc.e57", {} ) );
Expand Down

0 comments on commit 8d9663e

Please sign in to comment.