From 82c9a820d7f9ddc3365fbef80dedabe309b11c9c Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Fri, 20 Nov 2020 21:18:18 +0000 Subject: [PATCH] gifload: ensure total height of all pages is sanitised --- .../sharpen_fuzzer-5806172036399104 | Bin 0 -> 954923 bytes libvips/foreign/gifload.c | 8 +++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 fuzz/common_fuzzer_corpus/sharpen_fuzzer-5806172036399104 diff --git a/fuzz/common_fuzzer_corpus/sharpen_fuzzer-5806172036399104 b/fuzz/common_fuzzer_corpus/sharpen_fuzzer-5806172036399104 new file mode 100644 index 0000000000000000000000000000000000000000..d019aac1db610bb932ef3b86c0fcecf30c7c9a7a GIT binary patch literal 954923 zcmeI*v5wownucNOPL%4vlWerv2ovmL(=*u#IyIaczJR`gxu*qAJfVS!_ZlYmR*@>I z)Gar=)GCrCKE}be*5hur$olJjzrTvqfB(;a{pWxD-|0`+b)ULl!vEbJ{&nT`bNc%q z!#}(Juk!C6za#$CZu`l-Kv`}*bO5&9qgdEf2Bi*)$(b^2Fwfc(7YuU!M9=%TC@ z+I!}re|F{~)AdE+L^g)m6uA1cf-AUkQ69MR9KnHZ_~}esvxQM;(K= z+Aw+^UGE%b(@-+fs2=SH2shD^wOA2NUGu5AhuV&mB}hTb=Z;%LcdpZxW4@JdLOEG@b^@b08US@CI-225*+&%^%DC+1|vzy?5Mx z9QF<-cM?=TMe2qkQbdYK5tmTJ?ajX1d&kug?f}bcRP}41Zg?6`<7qsNr&&6(#pl}N zDyvI~15BDGPg}jG9bP_}FkZ7^lYY5hD2d6EaEc~Rky&H)vxe|hJ~ND`jDUI_TDrwDKG25;~NZzgyXX4}5$arDH*ODOl}t>&W|9AL5;;uI}^ zikK9WVp2?sN%b_klmwIG-6uz<^zNsWMlG*V)vv*Z>*jknxv6`YzTTyaSpA|o!19&3 z;lfcj@#5P+H%^+*{e<+smY}*JY8nF?0~!PQq?x@gnN0g{v)b_12i@Wg-rx=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CN`v*`r`U3g_`U3g_L~ssb;tk&54c_1l-r$Wsv_7;xv_7;x zv3*b)#<7%`{=#&!pbL zq()UgMRH@bd5x-m4R{()<7qsNr}4BoR-o_( zZ}0|h@CI-2#{D<$zd4)+LHC@`2**p?<-I}NAj@RMipDlUE zU*=ICZ&v*j$v5(id?Vk;H~my=-LtZQ;0@m34c_1l-sq?4r|G8!;VQ?0z5tD)QR;?9 z(Wp5z3UBZRZ}0|h@CI+hcCme(v7M*!G@i!Ocp6XRX*`Xm@w8|}8@MyPy81f621b$n zX#$i0RUV+!jk-}c>V|1*Jj~H}z#F{58@$0AyulldZjJ7BHoAElPvdDkji>Q6p2pL7 z8c&Nxw1K5$`vo>|k>wltM!u1608PG;Z{!>KM!u160uA9{4jfd^nDUK$Bj3n3@(rNP z0W`e98@$0Ayulm1(NEJ)(@)b+(@z^dZLWH|tNH=t8~H}Qk#FQ1`9{8xZ{!>KM!u16 z?Od;G+*2Kb?d|J`~>PuxCT|IeXn5cZa8NEo1(_#(aGNeF1#|eF1%eeA3Kb zmrSPpxBZ-$Kj!_zVam&T;tD#Yv~Uym5Ys|hNDIsPp>EWTx=}acR2HG~cIqAD6d5nC zGx=r%&xUc4CoeKj<7qstoFD2&-KZONBj3n3VJV=xY2ppu;7vJisu$+91DxiA%is35 z!@s)IlK5%Yb(eZTac@!=HYdd*&wE7a^{?^oum7i)-;#c0|M%g?j$5Ao{`zY8eA@Lt w^RM*lTx^kg&%fVy`~K};zR_2Q{&wZi!`nF@IzNr4-{*gy)BDfgWIPxD4_rnBUH||9 literal 0 HcmV?d00001 diff --git a/libvips/foreign/gifload.c b/libvips/foreign/gifload.c index 0eec998c..d7cc4975 100644 --- a/libvips/foreign/gifload.c +++ b/libvips/foreign/gifload.c @@ -700,8 +700,14 @@ vips_foreign_load_gif_scan_extension( VipsForeignLoadGif *gif ) static int vips_foreign_load_gif_set_header( VipsForeignLoadGif *gif, VipsImage *image ) { + const gint64 total_height = (gint64) gif->file->SHeight * gif->n; + if ( total_height <= 0 || total_height > VIPS_MAX_COORD ) { + vips_error( "gifload", "%s", + _( "image size out of bounds" ) ); + return( -1 ); + } vips_image_init_fields( image, - gif->file->SWidth, gif->file->SHeight * gif->n, + gif->file->SWidth, (int) total_height, (gif->has_colour ? 3 : 1) + (gif->has_transparency ? 1 : 0), VIPS_FORMAT_UCHAR, VIPS_CODING_NONE, gif->has_colour ?