0001-fixed-another-unsigned-integer-overflow.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. From ce03ad7ef4e8aeefce79192bf5b6f69fae396f0c Mon Sep 17 00:00:00 2001
  2. From: Marcus Meissner <marcus@jet.franken.de>
  3. Date: Mon, 8 Jun 2020 17:27:06 +0200
  4. Subject: [PATCH] fixed another unsigned integer overflow
  5. first fixed by google in android fork,
  6. https://android.googlesource.com/platform/external/libexif/+/1e187b62682ffab5003c702657d6d725b4278f16%5E%21/#F0
  7. (use a more generic overflow check method, also check second overflow instance.)
  8. https://security-tracker.debian.org/tracker/CVE-2020-0198
  9. Downloaded from upstream commit:
  10. https://github.com/libexif/libexif/commit/ce03ad7ef4e8aeefce79192bf5b6f69fae396f0c
  11. Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
  12. ---
  13. libexif/exif-data.c | 10 ++++++----
  14. 1 file changed, 6 insertions(+), 4 deletions(-)
  15. diff --git a/libexif/exif-data.c b/libexif/exif-data.c
  16. index 8b280d3..b495726 100644
  17. --- a/libexif/exif-data.c
  18. +++ b/libexif/exif-data.c
  19. @@ -47,6 +47,8 @@
  20. #undef JPEG_MARKER_APP1
  21. #define JPEG_MARKER_APP1 0xe1
  22. +#define CHECKOVERFLOW(offset,datasize,structsize) (( offset >= datasize) || (structsize > datasize) || (offset > datasize - structsize ))
  23. +
  24. static const unsigned char ExifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00};
  25. struct _ExifDataPrivate
  26. @@ -327,7 +329,7 @@ exif_data_load_data_thumbnail (ExifData *data, const unsigned char *d,
  27. exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", "Bogus thumbnail offset (%u).", o);
  28. return;
  29. }
  30. - if (s > ds - o) {
  31. + if (CHECKOVERFLOW(o,ds,s)) {
  32. exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", "Bogus thumbnail size (%u), max would be %u.", s, ds-o);
  33. return;
  34. }
  35. @@ -420,9 +422,9 @@ exif_data_load_data_content (ExifData *data, ExifIfd ifd,
  36. }
  37. /* Read the number of entries */
  38. - if ((offset + 2 < offset) || (offset + 2 < 2) || (offset + 2 > ds)) {
  39. + if (CHECKOVERFLOW(offset, ds, 2)) {
  40. exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA, "ExifData",
  41. - "Tag data past end of buffer (%u > %u)", offset+2, ds);
  42. + "Tag data past end of buffer (%u+2 > %u)", offset, ds);
  43. return;
  44. }
  45. n = exif_get_short (d + offset, data->priv->order);
  46. @@ -431,7 +433,7 @@ exif_data_load_data_content (ExifData *data, ExifIfd ifd,
  47. offset += 2;
  48. /* Check if we have enough data. */
  49. - if (offset + 12 * n > ds) {
  50. + if (CHECKOVERFLOW(offset, ds, 12*n)) {
  51. n = (ds - offset) / 12;
  52. exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData",
  53. "Short data; only loading %hu entries...", n);