diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-01-10 09:45:15 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-01-10 09:45:15 +0000 |
commit | 610d995c3a6aa406ee93052e613a4cfe1a8888c6 (patch) | |
tree | 556d326743132a6732180319061e813125fcc012 | |
parent | 3cd6485ee95ed2b2c4cf8cd7b45a573a0aced175 (diff) |
ofz#395 leak in Bitmap::AcquireWriteAccess
Change-Id: Id67f0b8e82e0730eb35a14a6080bfa5b15d365c8
-rw-r--r-- | vcl/source/gdi/pngread.cxx | 74 |
1 files changed, 36 insertions, 38 deletions
diff --git a/vcl/source/gdi/pngread.cxx b/vcl/source/gdi/pngread.cxx index 8b006751f613..c0a0007f7466 100644 --- a/vcl/source/gdi/pngread.cxx +++ b/vcl/source/gdi/pngread.cxx @@ -76,9 +76,11 @@ private: std::vector<sal_uInt8>::iterator maDataIter; std::unique_ptr<Bitmap> mpBmp; - Bitmap::ScopedWriteAccess mpAcc; + Bitmap::ScopedWriteAccess mxAcc; std::unique_ptr<Bitmap> mpMaskBmp; + Bitmap::ScopedWriteAccess mxMaskAcc; std::unique_ptr<AlphaMask> mpAlphaMask; + AlphaMask::ScopedWriteAccess mxAlphaAcc; BitmapWriteAccess* mpMaskAcc; ZCodec mpZCodec; @@ -418,17 +420,10 @@ BitmapEx PNGReaderImpl::GetBitmapEx( const Size& rPreviewSizeHint ) } // release write access of the bitmaps - mpAcc.reset(); - - if ( mpMaskAcc ) - { - if ( mpAlphaMask ) - mpAlphaMask->ReleaseAccess( mpMaskAcc ); - else if ( mpMaskBmp ) - Bitmap::ReleaseAccess( mpMaskAcc ); - - mpMaskAcc = nullptr; - } + mxAcc.reset(); + mxMaskAcc.reset(); + mxAlphaAcc.reset(); + mpMaskAcc = nullptr; // return the resulting BitmapEx BitmapEx aRet; @@ -657,16 +652,17 @@ bool PNGReaderImpl::ImplReadHeader( const Size& rPreviewSizeHint ) return false; mpBmp = o3tl::make_unique<Bitmap>( maTargetSize, mnTargetDepth ); - mpAcc = Bitmap::ScopedWriteAccess(*mpBmp); - if( !mpAcc ) + mxAcc = Bitmap::ScopedWriteAccess(*mpBmp); + if (!mxAcc) return false; if ( mbAlphaChannel ) { mpAlphaMask = o3tl::make_unique<AlphaMask>( maTargetSize ); mpAlphaMask->Erase( 128 ); - mpMaskAcc = mpAlphaMask->AcquireWriteAccess(); - if( !mpMaskAcc ) + mxAlphaAcc = AlphaMask::ScopedWriteAccess(*mpAlphaMask); + mpMaskAcc = mxAlphaAcc.get(); + if (!mpMaskAcc) return false; } @@ -691,9 +687,9 @@ void PNGReaderImpl::ImplGetGrayPalette( sal_uInt16 nBitDepth ) if( nBitDepth == 2 ) nPaletteEntryCount = 16; - mpAcc->SetPaletteEntryCount( nPaletteEntryCount ); + mxAcc->SetPaletteEntryCount( nPaletteEntryCount ); for ( sal_uInt32 i = 0, nStart = 0; nStart < 256; i++, nStart += nAdd ) - mpAcc->SetPaletteColor( (sal_uInt16)i, BitmapColor( mpColorTable[ nStart ], + mxAcc->SetPaletteColor( (sal_uInt16)i, BitmapColor( mpColorTable[ nStart ], mpColorTable[ nStart ], mpColorTable[ nStart ] ) ); } @@ -701,17 +697,17 @@ bool PNGReaderImpl::ImplReadPalette() { sal_uInt16 nCount = static_cast<sal_uInt16>( mnChunkLen / 3 ); - if ( ( ( mnChunkLen % 3 ) == 0 ) && ( ( 0 < nCount ) && ( nCount <= 256 ) ) && mpAcc ) + if ( ( ( mnChunkLen % 3 ) == 0 ) && ( ( 0 < nCount ) && ( nCount <= 256 ) ) && mxAcc ) { mbPalette = true; - mpAcc->SetPaletteEntryCount( (sal_uInt16) nCount ); + mxAcc->SetPaletteEntryCount( (sal_uInt16) nCount ); for ( sal_uInt16 i = 0; i < nCount; i++ ) { sal_uInt8 nRed = mpColorTable[ *maDataIter++ ]; sal_uInt8 nGreen = mpColorTable[ *maDataIter++ ]; sal_uInt8 nBlue = mpColorTable[ *maDataIter++ ]; - mpAcc->SetPaletteColor( i, Color( nRed, nGreen, nBlue ) ); + mxAcc->SetPaletteColor( i, Color( nRed, nGreen, nBlue ) ); } } else @@ -781,12 +777,14 @@ bool PNGReaderImpl::ImplReadTransparent() if( bNeedAlpha) { mpAlphaMask = o3tl::make_unique<AlphaMask>( maTargetSize ); - mpMaskAcc = mpAlphaMask->AcquireWriteAccess(); + mxAlphaAcc = AlphaMask::ScopedWriteAccess(*mpAlphaMask); + mpMaskAcc = mxAlphaAcc.get(); } else { mpMaskBmp = o3tl::make_unique<Bitmap>( maTargetSize, 1 ); - mpMaskAcc = mpMaskBmp->AcquireWriteAccess(); + mxMaskAcc = Bitmap::ScopedWriteAccess(*mpMaskBmp); + mpMaskAcc = mxMaskAcc.get(); } mbTransparent = (mpMaskAcc != nullptr); if( !mbTransparent ) @@ -832,9 +830,9 @@ void PNGReaderImpl::ImplGetBackground() if ( mnChunkLen == 1 ) { sal_uInt16 nCol = *maDataIter++; - if ( nCol < mpAcc->GetPaletteEntryCount() ) + if ( nCol < mxAcc->GetPaletteEntryCount() ) { - mpAcc->Erase( mpAcc->GetPaletteColor( (sal_uInt8)nCol ) ); + mxAcc->Erase( mxAcc->GetPaletteColor( (sal_uInt8)nCol ) ); break; } } @@ -849,7 +847,7 @@ void PNGReaderImpl::ImplGetBackground() // the color type 0 and 4 is always greyscale, // so the return value can be used as index sal_uInt8 nIndex = ImplScaleColor(); - mpAcc->Erase( mpAcc->GetPaletteColor( nIndex ) ); + mxAcc->Erase( mxAcc->GetPaletteColor( nIndex ) ); } } break; @@ -862,7 +860,7 @@ void PNGReaderImpl::ImplGetBackground() sal_uInt8 nRed = ImplScaleColor(); sal_uInt8 nGreen = ImplScaleColor(); sal_uInt8 nBlue = ImplScaleColor(); - mpAcc->Erase( Color( nRed, nGreen, nBlue ) ); + mxAcc->Erase( Color( nRed, nGreen, nBlue ) ); } } break; @@ -1147,9 +1145,9 @@ void PNGReaderImpl::ImplDrawScanline( sal_uInt32 nXStart, sal_uInt32 nXAdd ) const sal_uInt32 nY = mnYpos >> mnPreviewShift; sal_uInt8* pTmp = mpInflateInBuf + 1; - if ( mpAcc->HasPalette() ) // alphachannel is not allowed by pictures including palette entries + if ( mxAcc->HasPalette() ) // alphachannel is not allowed by pictures including palette entries { - switch ( mpAcc->GetBitCount() ) + switch ( mxAcc->GetBitCount() ) { case 1 : { @@ -1314,8 +1312,8 @@ void PNGReaderImpl::ImplDrawScanline( sal_uInt32 nXStart, sal_uInt32 nXAdd ) { int nLineBytes = maOrigSize.Width(); if (mbPalette) - SanitizePaletteIndexes(pTmp, nLineBytes, mpAcc); - mpAcc->CopyScanline( nY, pTmp, ScanlineFormat::N8BitPal, nLineBytes ); + SanitizePaletteIndexes(pTmp, nLineBytes, mxAcc); + mxAcc->CopyScanline( nY, pTmp, ScanlineFormat::N8BitPal, nLineBytes ); } else { @@ -1406,7 +1404,7 @@ void PNGReaderImpl::ImplDrawScanline( sal_uInt32 nXStart, sal_uInt32 nXAdd ) // copy scanlines directly to bitmaps for content and alpha; use the formats which // are able to copy directly to BitmapBuffer - mpAcc->CopyScanline(nY, mpScanline, ScanlineFormat::N24BitTcBgr, maOrigSize.Width() * 3); + mxAcc->CopyScanline(nY, mpScanline, ScanlineFormat::N24BitTcBgr, maOrigSize.Width() * 3); mpMaskAcc->CopyScanline(nY, mpScanlineAlpha, ScanlineFormat::N8BitPal, maOrigSize.Width()); } else @@ -1538,7 +1536,7 @@ void PNGReaderImpl::ImplDrawScanline( sal_uInt32 nXStart, sal_uInt32 nXAdd ) // copy scanline directly to bitmap for content; use the format which is able to // copy directly to BitmapBuffer - mpAcc->CopyScanline(nY, mpScanline, ScanlineFormat::N24BitTcBgr, maOrigSize.Width() * 3); + mxAcc->CopyScanline(nY, mpScanline, ScanlineFormat::N24BitTcBgr, maOrigSize.Width() * 3); } else { @@ -1593,7 +1591,7 @@ void PNGReaderImpl::ImplSetPixel( sal_uInt32 nY, sal_uInt32 nX, const BitmapColo return; nX >>= mnPreviewShift; - mpAcc->SetPixel( nY, nX, rBitmapColor ); + mxAcc->SetPixel( nY, nX, rBitmapColor ); } void PNGReaderImpl::ImplSetPixel( sal_uInt32 nY, sal_uInt32 nX, sal_uInt8 nPalIndex ) @@ -1603,7 +1601,7 @@ void PNGReaderImpl::ImplSetPixel( sal_uInt32 nY, sal_uInt32 nX, sal_uInt8 nPalIn return; nX >>= mnPreviewShift; - mpAcc->SetPixelIndex( nY, nX, nPalIndex ); + mxAcc->SetPixelIndex( nY, nX, nPalIndex ); } void PNGReaderImpl::ImplSetTranspPixel( sal_uInt32 nY, sal_uInt32 nX, const BitmapColor& rBitmapColor, bool bTrans ) @@ -1613,7 +1611,7 @@ void PNGReaderImpl::ImplSetTranspPixel( sal_uInt32 nY, sal_uInt32 nX, const Bitm return; nX >>= mnPreviewShift; - mpAcc->SetPixel( nY, nX, rBitmapColor ); + mxAcc->SetPixel( nY, nX, rBitmapColor ); if ( bTrans ) mpMaskAcc->SetPixel( nY, nX, mcTranspColor ); @@ -1629,7 +1627,7 @@ void PNGReaderImpl::ImplSetAlphaPixel( sal_uInt32 nY, sal_uInt32 nX, return; nX >>= mnPreviewShift; - mpAcc->SetPixelIndex( nY, nX, nPalIndex ); + mxAcc->SetPixelIndex( nY, nX, nPalIndex ); mpMaskAcc->SetPixelIndex( nY, nX, ~nAlpha ); } @@ -1641,7 +1639,7 @@ void PNGReaderImpl::ImplSetAlphaPixel( sal_uInt32 nY, sal_uInt32 nX, return; nX >>= mnPreviewShift; - mpAcc->SetPixel( nY, nX, rBitmapColor ); + mxAcc->SetPixel( nY, nX, rBitmapColor ); if (!mpMaskAcc) return; mpMaskAcc->SetPixelIndex( nY, nX, ~nAlpha ); |