Blame SOURCES/0461-video-readers-png-Sanity-check-some-huffman-codes.patch

d18179
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d18179
From: Daniel Axtens <dja@axtens.net>
d18179
Date: Tue, 6 Jul 2021 19:19:11 +1000
d18179
Subject: [PATCH] video/readers/png: Sanity check some huffman codes
d18179
d18179
ASAN picked up two OOB global reads: we weren't checking if some code
d18179
values fit within the cplens or cpdext arrays. Check and throw an error
d18179
if not.
d18179
d18179
Signed-off-by: Daniel Axtens <dja@axtens.net>
d18179
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
d18179
(cherry picked from commit c3a8ab0cbd24153ec7b1f84a96ddfdd72ef8d117)
d18179
(cherry picked from commit 5d09addf58086aa11d5f9a91af5632ff87c2d2ee)
d18179
(cherry picked from commit ff12584f9376a472f37d4ec14213fd29bf3b233a)
d18179
(cherry picked from commit e953feb46429355bb09f2cd01886296068d48a7c)
d18179
---
d18179
 grub-core/video/readers/png.c | 6 ++++++
d18179
 1 file changed, 6 insertions(+)
d18179
d18179
diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c
d18179
index 24e972d1ba..6c37678c40 100644
d18179
--- a/grub-core/video/readers/png.c
d18179
+++ b/grub-core/video/readers/png.c
d18179
@@ -753,6 +753,9 @@ grub_png_read_dynamic_block (struct grub_png_data *data)
d18179
 	  int len, dist, pos;
d18179
 
d18179
 	  n -= 257;
d18179
+	  if (((unsigned int) n) >= ARRAY_SIZE (cplens))
d18179
+	    return grub_error (GRUB_ERR_BAD_FILE_TYPE,
d18179
+			       "png: invalid huff code");
d18179
 	  len = cplens[n];
d18179
 	  if (cplext[n])
d18179
 	    len += grub_png_get_bits (data, cplext[n]);
d18179
@@ -760,6 +763,9 @@ grub_png_read_dynamic_block (struct grub_png_data *data)
d18179
 	    return grub_errno;
d18179
 
d18179
 	  n = grub_png_get_huff_code (data, &data->dist_table);
d18179
+	  if (((unsigned int) n) >= ARRAY_SIZE (cpdist))
d18179
+	    return grub_error (GRUB_ERR_BAD_FILE_TYPE,
d18179
+			       "png: invalid huff code");
d18179
 	  dist = cpdist[n];
d18179
 	  if (cpdext[n])
d18179
 	    dist += grub_png_get_bits (data, cpdext[n]);