filter/source/graphicfilter/iras/iras.cxx | 22 +++++++++++++++++++--- include/sal/log-areas.dox | 1 + 2 files changed, 20 insertions(+), 3 deletions(-)
New commits: commit 584e98267c32a04ef1c8aa8ebf3bcf5ebe01b952 Author: Caolán McNamara <[email protected]> Date: Tue Feb 13 13:27:38 2018 +0000 ofz#6287 limit palette index Change-Id: I0bd71d7c471d6b7f9342118dfcaa321b78df3bc2 Reviewed-on: https://gerrit.libreoffice.org/49652 Tested-by: Jenkins <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Caolán McNamara <[email protected]> diff --git a/filter/source/graphicfilter/iras/iras.cxx b/filter/source/graphicfilter/iras/iras.cxx index 6dca245c2ba3..d12e4f92ad82 100644 --- a/filter/source/graphicfilter/iras/iras.cxx +++ b/filter/source/graphicfilter/iras/iras.cxx @@ -220,6 +220,22 @@ bool RASReader::ImplReadHeader() return mbStatus; } +namespace +{ + const Color& SanitizePaletteIndex(std::vector<Color> const & rvPalette, sal_uInt8 nIndex) + { + if (nIndex >= rvPalette.size()) + { + auto nSanitizedIndex = nIndex % rvPalette.size(); + SAL_WARN_IF(nIndex != nSanitizedIndex, "filter.ras", "invalid colormap index: " + << static_cast<unsigned int>(nIndex) << ", colormap len is: " + << rvPalette.size()); + nIndex = nSanitizedIndex; + } + return rvPalette[nIndex]; + } +} + bool RASReader::ImplReadBody(vcl::bitmap::RawBitmap& rBitmap, std::vector<Color> const & rvPalette) { sal_Int32 x, y; @@ -239,9 +255,9 @@ bool RASReader::ImplReadBody(vcl::bitmap::RawBitmap& rBitmap, std::vector<Color> if (!m_rRAS.good()) mbStatus = false; } - rBitmap.SetPixel(y, x, rvPalette[ + rBitmap.SetPixel(y, x, SanitizePaletteIndex(rvPalette, sal::static_int_cast< sal_uInt8 >( - nDat >> ( ( x & 7 ) ^ 7 ))] ); + nDat >> ( ( x & 7 ) ^ 7 )))); } if (!( ( x - 1 ) & 0x8 ) ) { @@ -259,7 +275,7 @@ bool RASReader::ImplReadBody(vcl::bitmap::RawBitmap& rBitmap, std::vector<Color> for (x = 0; x < mnWidth && mbStatus; ++x) { sal_uInt8 nDat = ImplGetByte(); - rBitmap.SetPixel(y, x, rvPalette[nDat]); + rBitmap.SetPixel(y, x, SanitizePaletteIndex(rvPalette, nDat)); if (!m_rRAS.good()) mbStatus = false; } diff --git a/include/sal/log-areas.dox b/include/sal/log-areas.dox index a3e25b8fea27..5c2ee4774143 100644 --- a/include/sal/log-areas.dox +++ b/include/sal/log-areas.dox @@ -229,6 +229,7 @@ certain functionality. @li @c filter.os2met @li @c filter.pdf @li @c filter.pict +@li @c filter.ras @li @c filter.svg @li @c filter.tiff @li @c filter.xmlfa _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
