Sophie

Sophie

distrib > Mageia > 7 > aarch64 > by-pkgid > e495bfb0c3db167421e07edd8769eed1 > files > 7

python-pillow-5.4.1-1.3.mga7.src.rpm

From f6926a041b4b544fd2ced3752542afb6c8c19405 Mon Sep 17 00:00:00 2001
From: Eric Soroos <eric-github@soroos.net>
Date: Thu, 5 Mar 2020 09:11:13 +0000
Subject: [PATCH 02/11] Refactor to macro

---
 src/libImaging/FliDecode.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

--- a/src/libImaging/FliDecode.c
+++ b/src/libImaging/FliDecode.c
@@ -24,7 +24,12 @@
 #define	I32(ptr)\
     ((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24))
 
-
+#define ERR_IF_DATA_OOB(offset) \
+  if ((data + (offset)) > ptr + bytes) {\
+    state->errcode = IMAGING_CODEC_OVERRUN; \
+    return -1; \
+  }
+    
 int
 ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
 {
@@ -170,21 +175,15 @@ ImagingFliDecode(Imaging im, ImagingCode
 		UINT8* out = (UINT8*) im->image[y];
 		data += 1; /* ignore packetcount byte */
 		for (x = 0; x < state->xsize; x += i) {
-		    if (data + 2 > ptr + bytes ) {
-			/* Out of Bounds Read issue, guaranteed to try to read 2 from data */
-			state->errcode = IMAGING_CODEC_OVERRUN;
-			return -1;
-		    }
+		    /* Out of Bounds Read issue, guaranteed to try to read 2 from data */
+		    ERR_IF_DATA_OOB(2)
 		    if (data[0] & 0x80) {
 			i = 256 - data[0];
 			if (x + i > state->xsize) {
 			    break; /* safety first */
 			}
-			if (data + i + 1 > ptr + bytes ) {
-			    /* Out of Bounds Read issue */
-			    state->errcode = IMAGING_CODEC_OVERRUN;
-			    return -1;
-			}
+			/* Out of Bounds read issue */
+			ERR_IF_DATA_OOB(i+1)
 			memcpy(out + x, data + 1, i);
 			data += i + 1;
 		    } else {