nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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