nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0436-video-readers-jpeg-Don-t-decode-data-before-start-of.patch

468bd4
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
468bd4
From: Daniel Axtens <dja@axtens.net>
468bd4
Date: Fri, 15 Jan 2021 14:06:46 +1100
468bd4
Subject: [PATCH] video/readers/jpeg: Don't decode data before start of stream
468bd4
468bd4
When a start of stream marker is encountered, we call grub_jpeg_decode_sos()
468bd4
which allocates space for a bitmap.
468bd4
468bd4
When a restart marker is encountered, we call grub_jpeg_decode_data() which
468bd4
then fills in that bitmap.
468bd4
468bd4
If we get a restart marker before the start of stream marker, we will
468bd4
attempt to write to a bitmap_ptr that hasn't been allocated. Catch this
468bd4
and bail out. This fixes an attempt to write to NULL.
468bd4
468bd4
Signed-off-by: Daniel Axtens <dja@axtens.net>
468bd4
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
468bd4
---
468bd4
 grub-core/video/readers/jpeg.c | 4 ++++
468bd4
 1 file changed, 4 insertions(+)
468bd4
468bd4
diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c
030dc3
index e5148120f69..e31602f766a 100644
468bd4
--- a/grub-core/video/readers/jpeg.c
468bd4
+++ b/grub-core/video/readers/jpeg.c
468bd4
@@ -646,6 +646,10 @@ grub_jpeg_decode_data (struct grub_jpeg_data *data)
468bd4
   nr1 = (data->image_height + vb - 1) >> (3 + data->log_vs);
468bd4
   nc1 = (data->image_width + hb - 1)  >> (3 + data->log_hs);
468bd4
 
468bd4
+  if (data->bitmap_ptr == NULL)
468bd4
+    return grub_error(GRUB_ERR_BAD_FILE_TYPE,
468bd4
+		      "jpeg: attempted to decode data before start of stream");
468bd4
+
468bd4
   for (; data->r1 < nr1 && (!data->dri || rst);
468bd4
        data->r1++, data->bitmap_ptr += (vb * data->image_width - hb * nc1) * 3)
468bd4
     for (c1 = 0;  c1 < nc1 && (!data->dri || rst);