]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
video/readers/jpeg: Fix possible invalid loop boundary condition
authorDarren Kenny <darren.kenny@oracle.com>
Tue, 5 Apr 2022 18:25:52 +0000 (18:25 +0000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Wed, 20 Apr 2022 16:29:00 +0000 (18:29 +0200)
The value of next_marker is adjusted based on the word sized value
read from data->file.

The updated next_marker value should reference a location in the file
just beyond the huffman table, and as such should not have a value
larger than the size of the file.

Fixes: CID 73657
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/video/readers/jpeg.c

index e31602f766ae05c6cdb92e5b08c3d56263b7ddcc..c47ffd65151e040dc545aceb80eda652f660fbb3 100644 (file)
@@ -199,6 +199,12 @@ grub_jpeg_decode_huff_table (struct grub_jpeg_data *data)
   next_marker = data->file->offset;
   next_marker += grub_jpeg_get_word (data);
 
+  if (next_marker > data->file->size)
+    {
+      return grub_error (GRUB_ERR_BAD_FILE_TYPE,
+                        "jpeg: invalid huffman table");
+    }
+
   while (data->file->offset + sizeof (count) + 1 <= next_marker)
     {
       id = grub_jpeg_get_byte (data);