summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-01-07 17:22:25 +0000
committerCaolán McNamara <caolanm@redhat.com>2017-01-07 17:25:32 +0000
commit7160b8fb05dc45f9d896a3269b732f2101021521 (patch)
tree31745352a26e34025371c2318d72d6a317973716 /vcl
parent95e6ef5907436b886f58bc99fb8841e9b25a6139 (diff)
come up with a conservative max compression ratio for gifs
Change-Id: I01bc452a0bcc003bf9b7b65d9a2a49b6c1acebc1
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/filter/igif/gifread.cxx16
1 files changed, 16 insertions, 0 deletions
diff --git a/vcl/source/filter/igif/gifread.cxx b/vcl/source/filter/igif/gifread.cxx
index 3789ebbc8093..90f744fe69d2 100644
--- a/vcl/source/filter/igif/gifread.cxx
+++ b/vcl/source/filter/igif/gifread.cxx
@@ -61,6 +61,7 @@ class GIFReader : public GraphicReader
Bitmap::ScopedWriteAccess pAcc1;
long nYAcc;
long nLastPos;
+ sal_uInt64 nMaxStreamData;
sal_uInt32 nLogWidth100;
sal_uInt32 nLogHeight100;
sal_uInt16 nTimer;
@@ -113,6 +114,7 @@ GIFReader::GIFReader( SvStream& rStm )
, rIStm ( rStm )
, nYAcc ( 0 )
, nLastPos ( rStm.Tell() )
+ , nMaxStreamData( rStm.remainingSize() )
, nLogWidth100 ( 0UL )
, nLogHeight100 ( 0UL )
, nGlobalWidth ( 0 )
@@ -169,6 +171,20 @@ void GIFReader::CreateBitmaps( long nWidth, long nHeight, BitmapPalette* pPal,
}
#endif
+ // "Overall data compression asymptotically approaches 3839 × 8 / 12 = 2559 1/3"
+ // so assume compression of 1:2560 is possible
+ // (http://cloudinary.com/blog/a_one_color_image_is_worth_two_thousand_words suggests
+ // 1:1472.88 [184.11 x 8] is more realistic)
+ const sal_uInt64 nMinFileData = nWidth * nHeight / 2560;
+ if (nMaxStreamData < nMinFileData)
+ {
+ //there is nowhere near enough data in this stream to fill the claimed dimensions
+ SAL_WARN("vcl.filter", "gif claims dimensions " << nWidth << " x " << nHeight <<
+ " but filesize of " << nMaxStreamData << " is surely insufficiently large to fill it");
+ bStatus = false;
+ return;
+ }
+
if( bGCTransparent )
{
const Color aWhite( COL_WHITE );