nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0248-video-readers-jpeg-Refuse-to-handle-multiple-start-o.patch

e28c09
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
e28c09
From: Daniel Axtens <dja@axtens.net>
e28c09
Date: Mon, 28 Jun 2021 14:25:17 +1000
e28c09
Subject: [PATCH] video/readers/jpeg: Refuse to handle multiple start of
e28c09
 streams
e28c09
e28c09
An invalid file could contain multiple start of stream blocks, which
e28c09
would cause us to reallocate and leak our bitmap. Refuse to handle
e28c09
multiple start of streams.
e28c09
e28c09
Additionally, fix a grub_error() call formatting.
e28c09
e28c09
Signed-off-by: Daniel Axtens <dja@axtens.net>
e28c09
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
e28c09
(cherry picked from commit f3a854def3e281b7ad4bbea730cd3046de1da52f)
e28c09
(cherry picked from commit db0154828989a0a52ee59a4dda8c3803752bc827)
e28c09
---
e28c09
 grub-core/video/readers/jpeg.c | 7 +++++--
e28c09
 1 file changed, 5 insertions(+), 2 deletions(-)
e28c09
e28c09
diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c
e28c09
index caa211f06d..1df1171d78 100644
e28c09
--- a/grub-core/video/readers/jpeg.c
e28c09
+++ b/grub-core/video/readers/jpeg.c
e28c09
@@ -677,6 +677,9 @@ grub_jpeg_decode_sos (struct grub_jpeg_data *data)
e28c09
   if (data->file->offset != data_offset)
e28c09
     return grub_error (GRUB_ERR_BAD_FILE_TYPE, "jpeg: extra byte in sos");
e28c09
 
e28c09
+  if (*data->bitmap)
e28c09
+    return grub_error (GRUB_ERR_BAD_FILE_TYPE, "jpeg: too many start of scan blocks");
e28c09
+
e28c09
   if (grub_video_bitmap_create (data->bitmap, data->image_width,
e28c09
 				data->image_height,
e28c09
 				GRUB_VIDEO_BLIT_FORMAT_RGB_888))
e28c09
@@ -699,8 +702,8 @@ grub_jpeg_decode_data (struct grub_jpeg_data *data)
e28c09
   nc1 = (data->image_width + hb - 1)  >> (3 + data->log_hs);
e28c09
 
e28c09
   if (data->bitmap_ptr == NULL)
e28c09
-    return grub_error(GRUB_ERR_BAD_FILE_TYPE,
e28c09
-		      "jpeg: attempted to decode data before start of stream");
e28c09
+    return grub_error (GRUB_ERR_BAD_FILE_TYPE,
e28c09
+		       "jpeg: attempted to decode data before start of stream");
e28c09
 
e28c09
   for (; data->r1 < nr1 && (!data->dri || rst);
e28c09
        data->r1++, data->bitmap_ptr += (vb * data->image_width - hb * nc1) * 3)