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

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