Skip to content

Commit c553edb

Browse files
committed
Tk Ticket [822330269b]: int overflow save check from Tk commit
[https://core.tcl-lang.org/tk/vinfo/e129a2efc25f636e?diff=1] Thanks, Jan !
1 parent 0d31f12 commit c553edb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

generic/tkImgSVG.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ RasterizeSVG(
602602
unsigned char *imgData;
603603
Tk_PhotoImageBlock svgblock;
604604
double scale;
605+
Tcl_WideUInt wh;
605606
(void)srcX;
606607
(void)srcY;
607608

@@ -616,13 +617,14 @@ RasterizeSVG(
616617
}
617618

618619
/* Tk Ticket [822330269b] Check potential int overflow in following ckalloc */
619-
if ( w * h < 0 || w * h > INT_MAX / 4) {
620+
wh = (Tcl_WideUInt)w * (Tcl_WideUInt)h;
621+
if ( w < 0 || h < 0 || wh > INT_MAX / 4) {
620622
Tcl_SetObjResult(interp, Tcl_NewStringObj("image size overflow", -1));
621623
Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "IMAGE_SIZE_OVERFLOW", NULL);
622624
goto cleanRAST;
623625
}
624626

625-
imgData = (unsigned char *)attemptckalloc(w * h *4);
627+
imgData = (unsigned char *)attemptckalloc(wh * 4);
626628
if (imgData == NULL) {
627629
Tcl_SetObjResult(interp, Tcl_NewStringObj("cannot alloc image buffer", -1));
628630
Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "OUT_OF_MEMORY", NULL);

0 commit comments

Comments
 (0)