From f177b5fc32013a15cff864d7a42ac7486d282e67 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Thu, 31 Oct 2024 19:31:21 +0800 Subject: [PATCH] gif: Fix potential infinite loop --- src/image-gif.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/image-gif.c b/src/image-gif.c index 41cbc43..867fa10 100644 --- a/src/image-gif.c +++ b/src/image-gif.c @@ -465,7 +465,8 @@ static void read_ext(twin_gif_t *gif) { uint8_t label; - read(gif->fd, &label, 1); + if (read(gif->fd, &label, 1) < 1) + return; switch (label) { case 0x01: read_plain_text_ext(gif); @@ -494,11 +495,11 @@ static int gif_get_frame(twin_gif_t *gif) while (sep != ',') { if (sep == ';') return 0; - if (sep == '!') - read_ext(gif); - else + if (sep != '!') + return -1; + read_ext(gif); + if (read(gif->fd, &sep, 1) < 1) return -1; - read(gif->fd, &sep, 1); } if (read_image(gif) == -1) return -1;