summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-09-24 13:01:15 +0100
committerCaolán McNamara <caolanm@redhat.com>2017-09-24 15:21:24 +0200
commit1524f58340e3a6b87244e23d6d9536f25daaf550 (patch)
tree78ac2de96f691f12a76c47de2040e04a06e07adf /filter
parent10e5729fb07d6b4c66182596bd86734d0ab386b9 (diff)
move sanity checks before allocation
Change-Id: I7374b3cc4cb7f2be9cec71a385899051288234c9 Reviewed-on: https://gerrit.libreoffice.org/42706 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'filter')
-rw-r--r--filter/source/graphicfilter/itiff/itiff.cxx70
1 files changed, 35 insertions, 35 deletions
diff --git a/filter/source/graphicfilter/itiff/itiff.cxx b/filter/source/graphicfilter/itiff/itiff.cxx
index 0c5c89737642..9e5c6c62cfc0 100644
--- a/filter/source/graphicfilter/itiff/itiff.cxx
+++ b/filter/source/graphicfilter/itiff/itiff.cxx
@@ -518,12 +518,12 @@ bool TIFFReader::ReadMap()
{
for (sal_uInt32 np = 0; np < nPlanes; ++np)
{
+ if (np >= SAL_N_ELEMENTS(aMap))
+ return false;
sal_uInt32 nStrip = ny / GetRowsPerStrip() + np * nStripsPerPlane;
if ( nStrip >= aStripOffsets.size())
return false;
pTIFF->Seek( aStripOffsets[ nStrip ] + ( ny % GetRowsPerStrip() ) * nStripBytesPerRow );
- if (np >= SAL_N_ELEMENTS(aMap))
- return false;
pTIFF->ReadBytes(aMap[np].data(), nBytesPerRow);
if (!pTIFF->good())
return false;
@@ -1340,49 +1340,49 @@ bool TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
else
nDstBitsPerPixel = 8;
+ if ( nPlanarConfiguration == 1 )
+ nPlanes = 1;
+ else
+ nPlanes = nSamplesPerPixel;
+
+ if ( ( nFillOrder == 2 ) && ( nCompression != 5 ) ) // in the LZW mode bits are already being inverted
+ bByteSwap = true;
+
+ nStripsPerPlane = ( nImageLength - 1 ) / GetRowsPerStrip() + 1;
+ bStatus = nPlanes != 0;
+ }
+
+ if ( bStatus )
+ {
+ sal_uInt64 nRowSize = (static_cast<sal_uInt64>(nImageWidth) * nSamplesPerPixel / nPlanes * nBitsPerSample + 7) >> 3;
+ if (nRowSize > SAL_MAX_INT32 / SAL_N_ELEMENTS(aMap))
+ {
+ SAL_WARN("filter.tiff", "Ludicrous row size of: " << nRowSize << " required");
+ bStatus = false;
+ }
+ else
+ nBytesPerRow = nRowSize;
+ }
+
+ if ( bStatus )
+ {
pAlphaMask.reset();
Size aTargetSize(nImageWidth, nImageLength);
aBitmap = Bitmap(aTargetSize, nDstBitsPerPixel);
xAcc = Bitmap::ScopedWriteAccess(aBitmap);
if (xAcc && xAcc->Width() == nImageWidth && xAcc->Height() == nImageLength)
{
- if ( nPlanarConfiguration == 1 )
- nPlanes = 1;
- else
- nPlanes = nSamplesPerPixel;
-
- if ( ( nFillOrder == 2 ) && ( nCompression != 5 ) ) // in the LZW mode bits are already being inverted
- bByteSwap = true;
-
- nStripsPerPlane = ( nImageLength - 1 ) / GetRowsPerStrip() + 1;
- bStatus = nPlanes != 0;
-
- if (bStatus)
+ for (auto& j : aMap)
{
- sal_uInt64 nRowSize = (static_cast<sal_uInt64>(nImageWidth) * nSamplesPerPixel / nPlanes * nBitsPerSample + 7) >> 3;
- if (nRowSize > SAL_MAX_INT32 / SAL_N_ELEMENTS(aMap))
+ try
{
- SAL_WARN("filter.tiff", "Ludicrous row size of: " << nRowSize << " required");
- bStatus = false;
+ j.resize(nBytesPerRow);
}
- else
- nBytesPerRow = nRowSize;
- }
-
- if (bStatus)
- {
- for (auto& j : aMap)
+ catch (const std::bad_alloc &)
{
- try
- {
- j.resize(nBytesPerRow);
- }
- catch (const std::bad_alloc &)
- {
- j.clear();
- bStatus = false;
- break;
- }
+ j.clear();
+ bStatus = false;
+ break;
}
}