Menu ▾ ▴

#216 Stack buffer overflow in giftool via unbounded image count from untrusted GIF input

v1.0_(example)
open
nobody
None
1
2026-11-04
2026-11-04
No

Affected code:

int selected[MAX_IMAGES], nselected = 0; // MAX_IMAGES = 2048, line 118
...
for (i = nselected = 0; i < GifFileIn->ImageCount; i++) {
selected[nselected++] = i; // no bound check, line 245
}

In the default code path (no -n flag), this loop copies one index per image in the input GIF into a fixed 2048-entry stack array,
bounded only by GifFileIn->ImageCount — which dgif_lib.c increments once per image block with no cap. A GIF with more than 2048
image-descriptor blocks overflows selected[], corrupting stack memory. Reachable via plain giftool < malicious.gif, no flags
needed.

Fix: bound the loop by MAX_IMAGES, or size selected dynamically to ImageCount.

Found by VISHAP, a static-analysis pipeline, manually verified against source before
reporting.

Discussion


Log in to post a comment.