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

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