nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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