Skip to content

Commit

Permalink
PDF: avoid division by zero when generating from vector content whose…
Browse files Browse the repository at this point in the history
… bounding box is almost a horizontal or vertical line. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=13408. Credit to OSS Fuzz
  • Loading branch information
rouault committed Feb 26, 2019
1 parent ea4800d commit afbb4e3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions gdal/frmts/pdf/pdfwritabledataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,24 @@ OGRErr PDFWritableVectorDataset::SyncToDisk()
if (dfRatio < 1)
{
nWidth = 1024;
nHeight = static_cast<int>(nWidth * dfRatio);
const double dfHeight = nWidth * dfRatio;
if( dfHeight < 1 || dfHeight > INT_MAX || CPLIsNan(dfHeight) )
{
CPLError(CE_Failure, CPLE_AppDefined, "Invalid image dimensions");
return OGRERR_FAILURE;
}
nHeight = static_cast<int>(dfHeight);
}
else
{
nHeight = 1024;
nWidth = static_cast<int>(nHeight / dfRatio);
const double dfWidth = nHeight / dfRatio;
if( dfWidth < 1 || dfWidth > INT_MAX || CPLIsNan(dfWidth) )
{
CPLError(CE_Failure, CPLE_AppDefined, "Invalid image dimensions");
return OGRERR_FAILURE;
}
nWidth = static_cast<int>(dfWidth);
}

GDALDataset* poSrcDS = MEMDataset::Create( "MEM:::", nWidth, nHeight, 0, GDT_Byte, nullptr );
Expand Down

0 comments on commit afbb4e3

Please sign in to comment.