88ec22
From 697957b79a9473f0f643051265885fb048395127 Mon Sep 17 00:00:00 2001
88ec22
From: Lumir Balhar <lbalhar@redhat.com>
88ec22
Date: Wed, 4 Mar 2020 10:54:54 +0100
88ec22
Subject: [PATCH] CVE-2020-5313
88ec22
88ec22
---
88ec22
 src/libImaging/FliDecode.c | 8 ++++++--
88ec22
 1 file changed, 6 insertions(+), 2 deletions(-)
88ec22
88ec22
diff --git a/src/libImaging/FliDecode.c b/src/libImaging/FliDecode.c
88ec22
index a99aca8..72ba138 100644
88ec22
--- a/src/libImaging/FliDecode.c
88ec22
+++ b/src/libImaging/FliDecode.c
88ec22
@@ -40,8 +40,7 @@ ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
88ec22
 	return 0;
88ec22
 
88ec22
     /* We don't decode anything unless we have a full chunk in the
88ec22
-       input buffer (on the other hand, the Python part of the driver
88ec22
-       makes sure this is always the case) */
88ec22
+       input buffer */
88ec22
 
88ec22
     ptr = buf;
88ec22
 
88ec22
@@ -52,6 +51,11 @@ ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
88ec22
     /* Make sure this is a frame chunk.  The Python driver takes
88ec22
        case of other chunk types. */
88ec22
 
88ec22
+    if (bytes < 8) {
88ec22
+        state->errcode = IMAGING_CODEC_OVERRUN;
88ec22
+        return -1;
88ec22
+    }
88ec22
+
88ec22
     if (I16(ptr+4) != 0xF1FA) {
88ec22
 	state->errcode = IMAGING_CODEC_UNKNOWN;
88ec22
 	return -1;
88ec22
-- 
88ec22
2.24.1
88ec22