Skip to content

Commit f177b5f

Browse files
committed
gif: Fix potential infinite loop
1 parent 980bd4c commit f177b5f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/image-gif.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ static void read_ext(twin_gif_t *gif)
465465
{
466466
uint8_t label;
467467

468-
read(gif->fd, &label, 1);
468+
if (read(gif->fd, &label, 1) < 1)
469+
return;
469470
switch (label) {
470471
case 0x01:
471472
read_plain_text_ext(gif);
@@ -494,11 +495,11 @@ static int gif_get_frame(twin_gif_t *gif)
494495
while (sep != ',') {
495496
if (sep == ';')
496497
return 0;
497-
if (sep == '!')
498-
read_ext(gif);
499-
else
498+
if (sep != '!')
499+
return -1;
500+
read_ext(gif);
501+
if (read(gif->fd, &sep, 1) < 1)
500502
return -1;
501-
read(gif->fd, &sep, 1);
502503
}
503504
if (read_image(gif) == -1)
504505
return -1;

0 commit comments

Comments
 (0)