0099-video-readers-jpeg-Catch-files-with-unsupported-quan.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. From 693989598fd38c3c0b2a928f4f64865b5681762f Mon Sep 17 00:00:00 2001
  2. From: Daniel Axtens <dja@axtens.net>
  3. Date: Fri, 15 Jan 2021 12:57:04 +1100
  4. Subject: [PATCH] video/readers/jpeg: Catch files with unsupported quantization
  5. or Huffman tables
  6. Our decoder only supports 2 quantization tables. If a file asks for
  7. a quantization table with index > 1, reject it.
  8. Similarly, our decoder only supports 4 Huffman tables. If a file asks
  9. for a Huffman table with index > 3, reject it.
  10. This fixes some out of bounds reads. It's not clear what degree of control
  11. over subsequent execution could be gained by someone who can carefully
  12. set up the contents of memory before loading an invalid JPEG file.
  13. Signed-off-by: Daniel Axtens <dja@axtens.net>
  14. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  15. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  16. ---
  17. grub-core/video/readers/jpeg.c | 8 ++++++++
  18. 1 file changed, 8 insertions(+)
  19. diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c
  20. index 0b6ce3c..23f919a 100644
  21. --- a/grub-core/video/readers/jpeg.c
  22. +++ b/grub-core/video/readers/jpeg.c
  23. @@ -333,7 +333,11 @@ grub_jpeg_decode_sof (struct grub_jpeg_data *data)
  24. else if (ss != JPEG_SAMPLING_1x1)
  25. return grub_error (GRUB_ERR_BAD_FILE_TYPE,
  26. "jpeg: sampling method not supported");
  27. +
  28. data->comp_index[id][0] = grub_jpeg_get_byte (data);
  29. + if (data->comp_index[id][0] > 1)
  30. + return grub_error (GRUB_ERR_BAD_FILE_TYPE,
  31. + "jpeg: too many quantization tables");
  32. }
  33. if (data->file->offset != next_marker)
  34. @@ -602,6 +606,10 @@ grub_jpeg_decode_sos (struct grub_jpeg_data *data)
  35. ht = grub_jpeg_get_byte (data);
  36. data->comp_index[id][1] = (ht >> 4);
  37. data->comp_index[id][2] = (ht & 0xF) + 2;
  38. +
  39. + if ((data->comp_index[id][1] < 0) || (data->comp_index[id][1] > 3) ||
  40. + (data->comp_index[id][2] < 0) || (data->comp_index[id][2] > 3))
  41. + return grub_error (GRUB_ERR_BAD_FILE_TYPE, "jpeg: invalid hufftable index");
  42. }
  43. grub_jpeg_get_byte (data); /* Skip 3 unused bytes. */
  44. --
  45. 2.14.2