dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0419-video-readers-jpeg-Test-for-an-invalid-next-marker-r.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Darren Kenny <darren.kenny@oracle.com>
80913e
Date: Fri, 4 Dec 2020 15:39:00 +0000
80913e
Subject: [PATCH] video/readers/jpeg: Test for an invalid next marker reference
80913e
 from a jpeg file
80913e
80913e
While it may never happen, and potentially could be caught at the end of
80913e
the function, it is worth checking up front for a bad reference to the
80913e
next marker just in case of a maliciously crafted file being provided.
80913e
80913e
Fixes: CID 73694
80913e
80913e
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
80913e
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
80913e
---
80913e
 grub-core/video/readers/jpeg.c | 6 ++++++
80913e
 1 file changed, 6 insertions(+)
80913e
80913e
diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c
80913e
index 31359a4c9c8..0b6ce3cee64 100644
80913e
--- a/grub-core/video/readers/jpeg.c
80913e
+++ b/grub-core/video/readers/jpeg.c
80913e
@@ -253,6 +253,12 @@ grub_jpeg_decode_quan_table (struct grub_jpeg_data *data)
80913e
   next_marker = data->file->offset;
80913e
   next_marker += grub_jpeg_get_word (data);
80913e
 
80913e
+  if (next_marker > data->file->size)
80913e
+    {
80913e
+      /* Should never be set beyond the size of the file. */
80913e
+      return grub_error (GRUB_ERR_BAD_FILE_TYPE, "jpeg: invalid next reference");
80913e
+    }
80913e
+
80913e
   while (data->file->offset + sizeof (data->quan_table[id]) + 1
80913e
 	 <= next_marker)
80913e
     {