nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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