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

ofz#574 sanitize png palette indexes

Change-Id: I006ffdf5c8c751e7e07b133716022e2a9b154478
Reviewed-on: https://gerrit.libreoffice.org/34034Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 3e23beda
...@@ -1114,6 +1114,19 @@ void PNGReaderImpl::ImplApplyFilter() ...@@ -1114,6 +1114,19 @@ void PNGReaderImpl::ImplApplyFilter()
namespace namespace
{ {
sal_uInt8 SanitizePaletteIndex(sal_uInt8 nIndex, sal_uInt16 nPaletteEntryCount)
{
if (nIndex >= nPaletteEntryCount)
{
auto nSanitizedIndex = nIndex % nPaletteEntryCount;
SAL_WARN_IF(nIndex != nSanitizedIndex, "vcl", "invalid colormap index: "
<< static_cast<unsigned int>(nIndex) << ", colormap len is: "
<< nPaletteEntryCount);
nIndex = nSanitizedIndex;
}
return nIndex;
}
void SanitizePaletteIndexes(sal_uInt8* pEntries, int nLen, const Bitmap::ScopedWriteAccess& rAcc) void SanitizePaletteIndexes(sal_uInt8* pEntries, int nLen, const Bitmap::ScopedWriteAccess& rAcc)
{ {
sal_uInt16 nPaletteEntryCount = rAcc->GetPaletteEntryCount(); sal_uInt16 nPaletteEntryCount = rAcc->GetPaletteEntryCount();
...@@ -1602,7 +1615,7 @@ void PNGReaderImpl::ImplSetPixel( sal_uInt32 nY, sal_uInt32 nX, sal_uInt8 nPalIn ...@@ -1602,7 +1615,7 @@ void PNGReaderImpl::ImplSetPixel( sal_uInt32 nY, sal_uInt32 nX, sal_uInt8 nPalIn
return; return;
nX >>= mnPreviewShift; nX >>= mnPreviewShift;
mxAcc->SetPixelIndex( nY, nX, nPalIndex ); mxAcc->SetPixelIndex(nY, nX, SanitizePaletteIndex(nPalIndex, mxAcc->GetPaletteEntryCount()));
} }
void PNGReaderImpl::ImplSetTranspPixel( sal_uInt32 nY, sal_uInt32 nX, const BitmapColor& rBitmapColor, bool bTrans ) void PNGReaderImpl::ImplSetTranspPixel( sal_uInt32 nY, sal_uInt32 nX, const BitmapColor& rBitmapColor, bool bTrans )
...@@ -1628,7 +1641,7 @@ void PNGReaderImpl::ImplSetAlphaPixel( sal_uInt32 nY, sal_uInt32 nX, ...@@ -1628,7 +1641,7 @@ void PNGReaderImpl::ImplSetAlphaPixel( sal_uInt32 nY, sal_uInt32 nX,
return; return;
nX >>= mnPreviewShift; nX >>= mnPreviewShift;
mxAcc->SetPixelIndex( nY, nX, nPalIndex ); mxAcc->SetPixelIndex(nY, nX, SanitizePaletteIndex(nPalIndex, mxAcc->GetPaletteEntryCount()));
mpMaskAcc->SetPixel(nY, nX, BitmapColor(~nAlpha)); mpMaskAcc->SetPixel(nY, nX, BitmapColor(~nAlpha));
} }
......
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