Skip to content

Commit a3b638d

Browse files
rouaultgithub-actions[bot]
authored andcommitted
msSHPReadShape(): avoid integer overflow
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52209
1 parent 2721264 commit a3b638d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mapshape.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -1377,11 +1377,12 @@ void msSHPReadShape( SHPHandle psSHP, int hEntity, shapeObj *shape )
13771377
const ms_int32 end = i == nParts - 1
13781378
? nPoints
13791379
: psSHP->panParts[i+1];
1380-
shape->line[i].numpoints = end - psSHP->panParts[i];
13811380
if (psSHP->panParts[i] < 0 || end < 0 || end > nPoints ||
13821381
psSHP->panParts[i] >= end) {
1383-
msSetError(MS_SHPERR, "Corrupted .shp file : shape %d, shape->line[%d].numpoints=%d", "msSHPReadShape()",
1384-
hEntity, i, shape->line[i].numpoints);
1382+
msSetError(MS_SHPERR, "Corrupted .shp file : shape %d, shape->line[%d].start=%d, shape->line[%d].end=%d", "msSHPReadShape()",
1383+
hEntity,
1384+
i, psSHP->panParts[i],
1385+
i, end);
13851386
while(--i >= 0)
13861387
free(shape->line[i].point);
13871388
free(shape->line);
@@ -1391,6 +1392,7 @@ void msSHPReadShape( SHPHandle psSHP, int hEntity, shapeObj *shape )
13911392
return;
13921393
}
13931394

1395+
shape->line[i].numpoints = end - psSHP->panParts[i];
13941396
if( (shape->line[i].point = (pointObj *)malloc(sizeof(pointObj)*shape->line[i].numpoints)) == NULL ) {
13951397
while(--i >= 0)
13961398
free(shape->line[i].point);

0 commit comments

Comments
 (0)