From e05fb81a20541833a2d62ce08552b18c0920b9a1 Mon Sep 17 00:00:00 2001 From: Cosmin Truta Date: Sat, 25 Nov 2017 23:17:46 -0500 Subject: [PATCH] gifread: Detect indirect circular dependencies in LZW tables --- src/gifread/gifread.c | 4 +++- src/gifread/gifread.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gifread/gifread.c b/src/gifread/gifread.c index 0123456789abcdef..0123456789abcdef 100644 --- a/src/gifread/gifread.c +++ b/src/gifread/gifread.c @@ -5,7 +5,7 @@ * @author Cosmin Truta * * @section Copyright - * Copyright (C) 2003-2015 Cosmin Truta. + * Copyright (C) 2003-2017 Cosmin Truta. * This software was derived from "giftopnm.c" by David Koblas, * and is distributed under the same copyright and warranty terms. * @@ -499,6 +499,8 @@ static int LZWReadByte(int init_flag, int input_code_size, FILE *stream) *sp++ = table[1][code]; if (code == table[0][code]) GIFError("GIF/LZW error: circular table entry"); + if ((size_t)(sp - stack) >= sizeof(stack) / sizeof(stack[0])) + GIFError("GIF/LZW error: circular table"); code = table[0][code]; } diff --git a/src/gifread/gifread.h b/src/gifread/gifread.h index 0123456789abcdef..0123456789abcdef 100644 --- a/src/gifread/gifread.h +++ b/src/gifread/gifread.h @@ -5,7 +5,7 @@ * @author Cosmin Truta * * @section Copyright - * Copyright (C) 2003-2015 Cosmin Truta. + * Copyright (C) 2003-2017 Cosmin Truta. * This software was derived from "giftopnm.c" by David Koblas, * and is distributed under the same copyright and warranty terms. *