Kaydet (Commit) c2c3a82b authored tarafından Caolán McNamara's avatar Caolán McNamara

ofz#3593: alloc memory on demand to avoid up front oom

Change-Id: I5500a98f366deaa3d4a69a419163d39e5a9e4d92
Reviewed-on: https://gerrit.libreoffice.org/43278Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst bd9cf89f
...@@ -524,6 +524,14 @@ bool TIFFReader::ReadMap() ...@@ -524,6 +524,14 @@ bool TIFFReader::ReadMap()
if ( nStrip >= aStripOffsets.size()) if ( nStrip >= aStripOffsets.size())
return false; return false;
pTIFF->Seek( aStripOffsets[ nStrip ] + ( ny % GetRowsPerStrip() ) * nStripBytesPerRow ); 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); pTIFF->ReadBytes(aMap[np].data(), nBytesPerRow);
if (!pTIFF->good()) if (!pTIFF->good())
return false; return false;
...@@ -591,6 +599,14 @@ bool TIFFReader::ReadMap() ...@@ -591,6 +599,14 @@ bool TIFFReader::ReadMap()
} }
if (np >= SAL_N_ELEMENTS(aMap)) if (np >= SAL_N_ELEMENTS(aMap))
return false; 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); DecompressStatus aResult = aCCIDecom.DecompressScanline(aMap[np].data(), nImageWidth * nBitsPerSample * nSamplesPerPixel / nPlanes, np + 1 == nPlanes);
if (!aResult.m_bSuccess) if (!aResult.m_bSuccess)
return false; return false;
...@@ -636,6 +652,14 @@ bool TIFFReader::ReadMap() ...@@ -636,6 +652,14 @@ bool TIFFReader::ReadMap()
} }
if (np >= SAL_N_ELEMENTS(aMap)) if (np >= SAL_N_ELEMENTS(aMap))
return false; return false;
try
{
aMap[np].resize(nBytesPerRow);
}
catch (const std::bad_alloc &)
{
return false;
}
if ( ( aLZWDecom.Decompress(aMap[np].data(), nBytesPerRow) != nBytesPerRow ) || pTIFF->GetError() ) if ( ( aLZWDecom.Decompress(aMap[np].data(), nBytesPerRow) != nBytesPerRow ) || pTIFF->GetError() )
return false; return false;
} }
...@@ -663,6 +687,14 @@ bool TIFFReader::ReadMap() ...@@ -663,6 +687,14 @@ bool TIFFReader::ReadMap()
sal_uInt32 nRowBytesLeft = nBytesPerRow; sal_uInt32 nRowBytesLeft = nBytesPerRow;
if (np >= SAL_N_ELEMENTS(aMap)) if (np >= SAL_N_ELEMENTS(aMap))
return false; return false;
try
{
aMap[np].resize(nBytesPerRow);
}
catch (const std::bad_alloc &)
{
return false;
}
sal_uInt8* pdst = aMap[np].data(); sal_uInt8* pdst = aMap[np].data();
do do
{ {
...@@ -1481,20 +1513,6 @@ bool TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic ) ...@@ -1481,20 +1513,6 @@ bool TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
xAcc = Bitmap::ScopedWriteAccess(aBitmap); xAcc = Bitmap::ScopedWriteAccess(aBitmap);
if (xAcc && xAcc->Width() == nImageWidth && xAcc->Height() == nImageLength) 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()) if (bStatus && HasAlphaChannel())
{ {
pAlphaMask.reset( new AlphaMask( aTargetSize ) ); pAlphaMask.reset( new AlphaMask( aTargetSize ) );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment