[Libreoffice-commits] core.git: filter/source

Caolán McNamara caolanm at redhat.com
Mon Oct 9 13:53:27 UTC 2017


 filter/source/graphicfilter/itiff/itiff.cxx |   46 +++++++++++++++++++---------
 1 file changed, 32 insertions(+), 14 deletions(-)

New commits:
commit c2c3a82b2c1a7de4ea050e57c3b762059f8aee17
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Oct 9 13:02:57 2017 +0100

    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 at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

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 ) );


More information about the Libreoffice-commits mailing list