diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-10-09 13:02:57 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-10-09 15:53:06 +0200 |
commit | c2c3a82b2c1a7de4ea050e57c3b762059f8aee17 (patch) | |
tree | 16c99583d6d97f650062fbe724f05d13e9d358c5 /filter | |
parent | bd9cf89f6dc13da314d0dd6fc43512a8732ce125 (diff) |
ofz#3593: alloc memory on demand to avoid up front oom
Change-Id: I5500a98f366deaa3d4a69a419163d39e5a9e4d92
Reviewed-on: https://gerrit.libreoffice.org/43278
Tested-by: Jenkins <ci@libreoffice.org>
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.cxx | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/filter/source/graphicfilter/itiff/itiff.cxx b/filter/source/graphicfilter/itiff/itiff.cxx index 83dbc0b72424..c38ee4975540 100644 --- a/filter/source/graphicfilter/itiff/itiff.cxx +++ b/filter/source/graphicfilter/itiff/itiff.cxx @@ -524,6 +524,14 @@ bool TIFFReader::ReadMap() if ( nStrip >= aStripOffsets.size()) return false; pTIFF->Seek( aStripOffsets[ nStrip ] + ( ny % GetRowsPerStrip() ) * nStripBytesPerRow ); + try + { + aMap[np].resize(nBytesPerRow); + } + catch (const std::bad_alloc &) + { + return false; + } pTIFF->ReadBytes(aMap[np].data(), nBytesPerRow); if (!pTIFF->good()) return false; @@ -591,6 +599,14 @@ bool TIFFReader::ReadMap() } if (np >= SAL_N_ELEMENTS(aMap)) return false; + try + { + aMap[np].resize(nBytesPerRow); + } + catch (const std::bad_alloc &) + { + return false; + } DecompressStatus aResult = aCCIDecom.DecompressScanline(aMap[np].data(), nImageWidth * nBitsPerSample * nSamplesPerPixel / nPlanes, np + 1 == nPlanes); if (!aResult.m_bSuccess) return false; @@ -636,6 +652,14 @@ bool TIFFReader::ReadMap() } if (np >= SAL_N_ELEMENTS(aMap)) return false; + try + { + aMap[np].resize(nBytesPerRow); + } + catch (const std::bad_alloc &) + { + return false; + } if ( ( aLZWDecom.Decompress(aMap[np].data(), nBytesPerRow) != nBytesPerRow ) || pTIFF->GetError() ) return false; } @@ -663,6 +687,14 @@ bool TIFFReader::ReadMap() sal_uInt32 nRowBytesLeft = nBytesPerRow; if (np >= SAL_N_ELEMENTS(aMap)) return false; + try + { + aMap[np].resize(nBytesPerRow); + } + catch (const std::bad_alloc &) + { + return false; + } sal_uInt8* pdst = aMap[np].data(); do { @@ -1481,20 +1513,6 @@ bool TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic ) xAcc = Bitmap::ScopedWriteAccess(aBitmap); if (xAcc && xAcc->Width() == nImageWidth && xAcc->Height() == nImageLength) { - for (auto& j : aMap) - { - try - { - j.resize(nBytesPerRow); - } - catch (const std::bad_alloc &) - { - j.clear(); - bStatus = false; - break; - } - } - if (bStatus && HasAlphaChannel()) { pAlphaMask.reset( new AlphaMask( aTargetSize ) ); |