7f73fb
From f91c78960495efa04c7f12eeb916158d4bfbabc4 Mon Sep 17 00:00:00 2001
7f73fb
From: Lumir Balhar <lbalhar@redhat.com>
7f73fb
Date: Mon, 13 Jul 2020 15:40:11 +0200
7f73fb
Subject: [PATCH] CVE-2020-11538
7f73fb
7f73fb
---
7f73fb
 src/libImaging/SgiRleDecode.c | 8 ++++++--
7f73fb
 1 file changed, 6 insertions(+), 2 deletions(-)
7f73fb
7f73fb
diff --git a/src/libImaging/SgiRleDecode.c b/src/libImaging/SgiRleDecode.c
7f73fb
index 6367ae7..eb8fc84 100644
7f73fb
--- a/src/libImaging/SgiRleDecode.c
7f73fb
+++ b/src/libImaging/SgiRleDecode.c
7f73fb
@@ -28,6 +28,7 @@ static void read4B(UINT32* dest, UINT8* buf)
7f73fb
 static int expandrow(UINT8* dest, UINT8* src, int n, int z, int xsize)
7f73fb
 {
7f73fb
     UINT8 pixel, count;
7f73fb
+    int x = 0;
7f73fb
 
7f73fb
     for (;n > 0; n--)
7f73fb
     {
7f73fb
@@ -37,9 +38,10 @@ static int expandrow(UINT8* dest, UINT8* src, int n, int z, int xsize)
7f73fb
         count = pixel & RLE_MAX_RUN;
7f73fb
         if (!count)
7f73fb
             return count;
7f73fb
-        if (count > xsize) {
7f73fb
+        if (x + count > xsize) {
7f73fb
             return -1;
7f73fb
         }
7f73fb
+        x += count;
7f73fb
         if (pixel & RLE_COPY_FLAG) {
7f73fb
             while(count--) {
7f73fb
                 *dest = *src++;
7f73fb
@@ -63,6 +65,7 @@ static int expandrow2(UINT16* dest, UINT16* src, int n, int z, int xsize)
7f73fb
 {
7f73fb
     UINT8 pixel, count;
7f73fb
 
7f73fb
+    int x = 0;
7f73fb
 
7f73fb
     for (;n > 0; n--)
7f73fb
     {
7f73fb
@@ -73,9 +76,10 @@ static int expandrow2(UINT16* dest, UINT16* src, int n, int z, int xsize)
7f73fb
         count = pixel & RLE_MAX_RUN;
7f73fb
         if (!count)
7f73fb
             return count;
7f73fb
-        if (count > xsize) {
7f73fb
+        if (x + count > xsize) {
7f73fb
             return -1;
7f73fb
         }
7f73fb
+        x += count;
7f73fb
         if (pixel & RLE_COPY_FLAG) {
7f73fb
             while(count--) {
7f73fb
                 *dest = *src++;
7f73fb
-- 
7f73fb
2.26.2
7f73fb