diff --git a/generic/tkImgGIF.c b/generic/tkImgGIF.c index 63689721c..a58f8204b 100644 --- a/generic/tkImgGIF.c +++ b/generic/tkImgGIF.c @@ -498,7 +498,13 @@ FileReadGIF( */ if (Fread(gifConfPtr, buf, 1, 3, chan) != 3) { - return TCL_OK; + /* + * Bug [865af0148c]: 3 bytes should be there, but data ended before + */ + Tcl_SetObjResult(interp, Tcl_NewStringObj( + "GIF file truncated", -1)); + Tcl_SetErrorCode(interp, "TK", "IMAGE", "GIF", "TRUNCATED", NULL); + return TCL_ERROR; } bitPixel = 2 << (buf[0] & 0x07); diff --git a/tests/corruptTruncatedColormap.gif b/tests/corruptTruncatedColormap.gif new file mode 100644 index 000000000..21d4add9c Binary files /dev/null and b/tests/corruptTruncatedColormap.gif differ diff --git a/tests/imgPhoto.test b/tests/imgPhoto.test index 29e6b530e..0a2cf7f96 100644 --- a/tests/imgPhoto.test +++ b/tests/imgPhoto.test @@ -1938,6 +1938,23 @@ test imgPhoto-20.6 {Reject truncated GIF (file)} -setup { } -cleanup { catch {image delete gif1} } -returnCodes error -result {error reading color map} +test imgPhoto-20.6.1 {Reject truncated GIF in Colormap - ticket 865af0148c - file} -setup { + set fileName [file join [file dirname [info script]] corruptTruncatedColormap.gif] +} -body { + image create photo gif1 -file $fileName +} -cleanup { + catch {image delete gif1} +} -returnCodes error -result {GIF file truncated} +test imgPhoto-20.6.2 {Reject truncated GIF in Colormap - ticket 865af0148c - data} -setup { + set fileName [file join [file dirname [info script]] corruptTruncatedColormap.gif] + set h [open $fileName rb] + set d [read $h] + close $h +} -body { + image create photo gif1 -data $d +} -cleanup { + catch {image delete gif1} +} -returnCodes error -result {GIF file truncated} test imgPhoto-20.7 {Reject corrupted GIF (> 4Gb) (binary string)} -constraints { nonPortable } -setup {