Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | From 166a4d61448f74745afe1dac2f2cfb85d04909bf Mon Sep 17 00:00:00 2001 |
| 2 | From: Daniel Axtens <dja@axtens.net> |
| 3 | Date: Mon, 28 Jun 2021 14:25:17 +1000 |
| 4 | Subject: [PATCH] video/readers/jpeg: Refuse to handle multiple start of |
| 5 | streams |
| 6 | |
| 7 | An invalid file could contain multiple start of stream blocks, which |
| 8 | would cause us to reallocate and leak our bitmap. Refuse to handle |
| 9 | multiple start of streams. |
| 10 | |
| 11 | Additionally, fix a grub_error() call formatting. |
| 12 | |
| 13 | Signed-off-by: Daniel Axtens <dja@axtens.net> |
| 14 | Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> |
| 15 | |
| 16 | Upstream-Status: Backport |
| 17 | |
| 18 | Reference to upstream patch: |
| 19 | https://git.savannah.gnu.org/cgit/grub.git/commit/?id=166a4d61448f74745afe1dac2f2cfb85d04909bf |
| 20 | |
| 21 | Signed-off-by: Yongxin Liu <yongxin.liu@windriver.com> |
| 22 | --- |
| 23 | grub-core/video/readers/jpeg.c | 7 +++++-- |
| 24 | 1 file changed, 5 insertions(+), 2 deletions(-) |
| 25 | |
| 26 | diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c |
| 27 | index 2284a6c06..579bbe8a4 100644 |
| 28 | --- a/grub-core/video/readers/jpeg.c |
| 29 | +++ b/grub-core/video/readers/jpeg.c |
| 30 | @@ -683,6 +683,9 @@ grub_jpeg_decode_sos (struct grub_jpeg_data *data) |
| 31 | if (data->file->offset != data_offset) |
| 32 | return grub_error (GRUB_ERR_BAD_FILE_TYPE, "jpeg: extra byte in sos"); |
| 33 | |
| 34 | + if (*data->bitmap) |
| 35 | + return grub_error (GRUB_ERR_BAD_FILE_TYPE, "jpeg: too many start of scan blocks"); |
| 36 | + |
| 37 | if (grub_video_bitmap_create (data->bitmap, data->image_width, |
| 38 | data->image_height, |
| 39 | GRUB_VIDEO_BLIT_FORMAT_RGB_888)) |
| 40 | @@ -705,8 +708,8 @@ grub_jpeg_decode_data (struct grub_jpeg_data *data) |
| 41 | nc1 = (data->image_width + hb - 1) >> (3 + data->log_hs); |
| 42 | |
| 43 | if (data->bitmap_ptr == NULL) |
| 44 | - return grub_error(GRUB_ERR_BAD_FILE_TYPE, |
| 45 | - "jpeg: attempted to decode data before start of stream"); |
| 46 | + return grub_error (GRUB_ERR_BAD_FILE_TYPE, |
| 47 | + "jpeg: attempted to decode data before start of stream"); |
| 48 | |
| 49 | for (; data->r1 < nr1 && (!data->dri || rst); |
| 50 | data->r1++, data->bitmap_ptr += (vb * data->image_width - hb * nc1) * 3) |
| 51 | -- |
| 52 | 2.34.1 |
| 53 | |