@@ -1412,7 +1412,7 @@ OGRErr OGRSQLiteLayer::createFromSpatialiteInternal(
14121412 if (NEED_SWAP_SPATIALITE ())
14131413 CPL_SWAP32PTR (&nPointCount);
14141414
1415- if (nPointCount < 0 || nPointCount - 2 > (INT_MAX - 16 * 2 ) / 8 )
1415+ if (nPointCount < 0 || nPointCount > (INT_MAX - 16 * 2 ) / 8 + 2 )
14161416 return OGRERR_CORRUPT_DATA;
14171417
14181418 compressedSize = 16 * 2 ; // first and last Points
@@ -1482,7 +1482,7 @@ OGRErr OGRSQLiteLayer::createFromSpatialiteInternal(
14821482 if (NEED_SWAP_SPATIALITE ())
14831483 CPL_SWAP32PTR (&nPointCount);
14841484
1485- if (nPointCount < 0 || nPointCount - 2 > (INT_MAX - 24 * 2 ) / 12 )
1485+ if (nPointCount < 0 || nPointCount > (INT_MAX - 24 * 2 ) / 12 + 2 )
14861486 return OGRERR_CORRUPT_DATA;
14871487
14881488 compressedSize = 24 * 2 ; // first and last Points
@@ -1556,7 +1556,7 @@ OGRErr OGRSQLiteLayer::createFromSpatialiteInternal(
15561556 if (NEED_SWAP_SPATIALITE ())
15571557 CPL_SWAP32PTR (&nPointCount);
15581558
1559- if (nPointCount < 0 || nPointCount - 2 > (INT_MAX - 24 * 2 ) / 16 )
1559+ if (nPointCount < 0 || nPointCount > (INT_MAX - 24 * 2 ) / 16 + 2 )
15601560 return OGRERR_CORRUPT_DATA;
15611561
15621562 compressedSize = 24 * 2 ; // first and last Points
@@ -1630,7 +1630,7 @@ OGRErr OGRSQLiteLayer::createFromSpatialiteInternal(
16301630 if (NEED_SWAP_SPATIALITE ())
16311631 CPL_SWAP32PTR (&nPointCount);
16321632
1633- if (nPointCount < 0 || nPointCount - 2 > (INT_MAX - 32 * 2 ) / 20 )
1633+ if (nPointCount < 0 || nPointCount > (INT_MAX - 32 * 2 ) / 20 + 2 )
16341634 return OGRERR_CORRUPT_DATA;
16351635
16361636 compressedSize = 32 * 2 ; // first and last Points
@@ -2055,7 +2055,7 @@ OGRErr OGRSQLiteLayer::createFromSpatialiteInternal(
20552055 if (NEED_SWAP_SPATIALITE ())
20562056 CPL_SWAP32PTR (&nPointCount);
20572057
2058- if (nPointCount < 0 || nPointCount - 2 > (INT_MAX - 16 * 2 ) / 8 )
2058+ if (nPointCount < 0 || nPointCount > (INT_MAX - 16 * 2 ) / 8 + 2 )
20592059 {
20602060 delete poPoly;
20612061 return OGRERR_CORRUPT_DATA;
@@ -2157,7 +2157,7 @@ OGRErr OGRSQLiteLayer::createFromSpatialiteInternal(
21572157 if (NEED_SWAP_SPATIALITE ())
21582158 CPL_SWAP32PTR (&nPointCount);
21592159
2160- if (nPointCount < 0 || nPointCount - 2 > (INT_MAX - 24 * 2 ) / 12 )
2160+ if (nPointCount < 0 || nPointCount > (INT_MAX - 24 * 2 ) / 12 + 2 )
21612161 {
21622162 delete poPoly;
21632163 return OGRERR_CORRUPT_DATA;
@@ -2263,7 +2263,7 @@ OGRErr OGRSQLiteLayer::createFromSpatialiteInternal(
22632263 if (NEED_SWAP_SPATIALITE ())
22642264 CPL_SWAP32PTR (&nPointCount);
22652265
2266- if (nPointCount < 0 || nPointCount - 2 > (INT_MAX - 24 * 2 ) / 16 )
2266+ if (nPointCount < 0 || nPointCount > (INT_MAX - 24 * 2 ) / 16 + 2 )
22672267 {
22682268 delete poPoly;
22692269 return OGRERR_CORRUPT_DATA;
@@ -2370,7 +2370,7 @@ OGRErr OGRSQLiteLayer::createFromSpatialiteInternal(
23702370 if (NEED_SWAP_SPATIALITE ())
23712371 CPL_SWAP32PTR (&nPointCount);
23722372
2373- if (nPointCount < 0 || nPointCount - 2 > (INT_MAX - 32 * 2 ) / 20 )
2373+ if (nPointCount < 0 || nPointCount > (INT_MAX - 32 * 2 ) / 20 + 2 )
23742374 {
23752375 delete poPoly;
23762376 return OGRERR_CORRUPT_DATA;
0 commit comments