Skip to content

Commit eed04ed

Browse files
committed
[xms_tin] Fix potential overflow on malformed files
Check if chunk values are valid before assigning to faces Fixes a coverity scan overflowed constant error
1 parent 1098b28 commit eed04ed

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

mdal/frmts/mdal_xms_tin.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,30 @@ std::unique_ptr<MDAL::Mesh> MDAL::DriverXmsTin::load( const std::string &meshFil
133133

134134
Face &face = faces[i];
135135
face.resize( MAX_VERTICES_PER_FACE_TIN );
136-
face[0] = MDAL::toSizeT( chunks[0] ) - 1;
137-
face[1] = MDAL::toSizeT( chunks[1] ) - 1;
138-
face[2] = MDAL::toSizeT( chunks[2] ) - 1;
136+
137+
const size_t chunk0 = MDAL::toSizeT( chunks[0] );
138+
if ( chunk0 < 1 )
139+
{
140+
MDAL::Log::error( MDAL_Status::Err_IncompatibleMesh, name(), meshFile + " does not contain valid triangle definition (first chunk value is < 1)" );
141+
return nullptr;
142+
}
143+
face[0] = chunk0 - 1;
144+
145+
const size_t chunk1 = MDAL::toSizeT( chunks[1] );
146+
if ( chunk1 < 1 )
147+
{
148+
MDAL::Log::error( MDAL_Status::Err_IncompatibleMesh, name(), meshFile + " does not contain valid triangle definition (second chunk value is < 1)" );
149+
return nullptr;
150+
}
151+
face[1] = chunk1 - 1;
152+
153+
const size_t chunk2 = MDAL::toSizeT( chunks[2] );
154+
if ( chunk2 < 1 )
155+
{
156+
MDAL::Log::error( MDAL_Status::Err_IncompatibleMesh, name(), meshFile + " does not contain valid triangle definition (third chunk value is < 1)" );
157+
return nullptr;
158+
}
159+
face[2] = chunk2 - 1;
139160
}
140161

141162
// Final keyword

0 commit comments

Comments
 (0)