From 0237c15b2de17a715df9f6e15c97a72c22621f72 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Fri, 11 Sep 2015 15:38:01 +0100 Subject: check stream status more often Change-Id: I233c2fff9c06a81117f8114ccee83b53ea4026db (cherry picked from commit b43e03353aeb04ed74a272d98df03dd7c20f3478) Reviewed-on: https://gerrit.libreoffice.org/18505 Tested-by: Jenkins Reviewed-by: David Tardon --- filter/qa/cppunit/data/ras/fail/hang-1.ras | Bin 0 -> 40 bytes filter/source/graphicfilter/iras/iras.cxx | 47 ++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 filter/qa/cppunit/data/ras/fail/hang-1.ras diff --git a/filter/qa/cppunit/data/ras/fail/hang-1.ras b/filter/qa/cppunit/data/ras/fail/hang-1.ras new file mode 100644 index 000000000000..44dec67607b4 Binary files /dev/null and b/filter/qa/cppunit/data/ras/fail/hang-1.ras differ diff --git a/filter/source/graphicfilter/iras/iras.cxx b/filter/source/graphicfilter/iras/iras.cxx index 5877fa2b678a..e3209bd74109 100644 --- a/filter/source/graphicfilter/iras/iras.cxx +++ b/filter/source/graphicfilter/iras/iras.cxx @@ -222,31 +222,43 @@ bool RASReader::ImplReadBody(BitmapWriteAccess * pAcc) case 1 : for (y = 0; y < mnHeight && mbStatus; ++y) { - for ( x = 0; x < mnWidth; x++ ) + for (x = 0; x < mnWidth && mbStatus; ++x) { if (!(x & 7)) + { nDat = ImplGetByte(); + if (!m_rRAS.good()) + mbStatus = false; + } pAcc->SetPixelIndex( y, x, sal::static_int_cast< sal_uInt8 >( nDat >> ( ( x & 7 ) ^ 7 )) ); } - if (!( ( x - 1 ) & 0x8 ) ) ImplGetByte(); // WORD ALIGNMENT ??? - if (!m_rRAS.good()) - mbStatus = false; + if (!( ( x - 1 ) & 0x8 ) ) + { + ImplGetByte(); // WORD ALIGNMENT ??? + if (!m_rRAS.good()) + mbStatus = false; + } } break; case 8 : for (y = 0; y < mnHeight && mbStatus; ++y) { - for ( x = 0; x < mnWidth; x++ ) + for (x = 0; x < mnWidth && mbStatus; ++x) { nDat = ImplGetByte(); pAcc->SetPixelIndex( y, x, nDat ); + if (!m_rRAS.good()) + mbStatus = false; + } + if ( x & 1 ) + { + ImplGetByte(); // WORD ALIGNMENT ??? + if (!m_rRAS.good()) + mbStatus = false; } - if ( x & 1 ) ImplGetByte(); // WORD ALIGNMENT ??? - if (!m_rRAS.good()) - mbStatus = false; } break; @@ -257,7 +269,7 @@ bool RASReader::ImplReadBody(BitmapWriteAccess * pAcc) case 24 : for (y = 0; y < mnHeight && mbStatus; ++y) { - for ( x = 0; x < mnWidth; x++ ) + for (x = 0; x < mnWidth && mbStatus; ++x) { if ( mnType == RAS_TYPE_RGB_FORMAT ) { @@ -272,17 +284,22 @@ bool RASReader::ImplReadBody(BitmapWriteAccess * pAcc) nRed = ImplGetByte(); } pAcc->SetPixel ( y, x, BitmapColor( nRed, nGreen, nBlue ) ); + if (!m_rRAS.good()) + mbStatus = false; + } + if ( x & 1 ) + { + ImplGetByte(); // WORD ALIGNMENT ??? + if (!m_rRAS.good()) + mbStatus = false; } - if ( x & 1 ) ImplGetByte(); // WORD ALIGNMENT ??? - if (!m_rRAS.good()) - mbStatus = false; } break; case 32 : for (y = 0; y < mnHeight && mbStatus; ++y) { - for ( x = 0; x < mnWidth; x++ ) + for (x = 0; x < mnWidth && mbStatus; ++x) { nDat = ImplGetByte(); // pad byte > nil if ( mnType == RAS_TYPE_RGB_FORMAT ) @@ -298,9 +315,9 @@ bool RASReader::ImplReadBody(BitmapWriteAccess * pAcc) nRed = ImplGetByte(); } pAcc->SetPixel ( y, x, BitmapColor( nRed, nGreen, nBlue ) ); + if (!m_rRAS.good()) + mbStatus = false; } - if (!m_rRAS.good()) - mbStatus = false; } break; } -- cgit