Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 1 | From ca71eda33fe8421f98fbe20eb4392473357c1c43 Mon Sep 17 00:00:00 2001 |
| 2 | From: Changqing Li <changqing.li@windriver.com> |
| 3 | Date: Wed, 30 Dec 2020 10:22:47 +0800 |
| 4 | Subject: [PATCH] fixed another unsigned integer overflow |
| 5 | |
| 6 | first fixed by google in android fork, |
| 7 | https://android.googlesource.com/platform/external/libexif/+/1e187b62682ffab5003c702657d6d725b4278f16%5E%21/#F0 |
| 8 | |
| 9 | (use a more generic overflow check method, also check second overflow instance.) |
| 10 | |
| 11 | https://security-tracker.debian.org/tracker/CVE-2020-0198 |
| 12 | |
| 13 | Upstream-Status: Backport[https://github.com/libexif/libexif/commit/ce03ad7ef4e8aeefce79192bf5b6f69fae396f0c] |
| 14 | CVE: CVE-2020-0198 |
| 15 | |
| 16 | Signed-off-by: Changqing Li <changqing.li@windriver.com> |
| 17 | --- |
| 18 | libexif/exif-data.c | 10 ++++++---- |
| 19 | 1 file changed, 6 insertions(+), 4 deletions(-) |
| 20 | |
| 21 | diff --git a/libexif/exif-data.c b/libexif/exif-data.c |
| 22 | index 8b280d3..34d58fc 100644 |
| 23 | --- a/libexif/exif-data.c |
| 24 | +++ b/libexif/exif-data.c |
| 25 | @@ -47,6 +47,8 @@ |
| 26 | #undef JPEG_MARKER_APP1 |
| 27 | #define JPEG_MARKER_APP1 0xe1 |
| 28 | |
| 29 | +#define CHECKOVERFLOW(offset,datasize,structsize) (( offset >= datasize) || (structsize > datasize) || (offset > datasize - structsize )) |
| 30 | + |
| 31 | static const unsigned char ExifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00}; |
| 32 | |
| 33 | struct _ExifDataPrivate |
| 34 | @@ -327,7 +329,7 @@ exif_data_load_data_thumbnail (ExifData *data, const unsigned char *d, |
| 35 | exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", "Bogus thumbnail offset (%u).", o); |
| 36 | return; |
| 37 | } |
| 38 | - if (s > ds - o) { |
| 39 | + if (CHECKOVERFLOW(o,ds,s)) { |
| 40 | exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", "Bogus thumbnail size (%u), max would be %u.", s, ds-o); |
| 41 | return; |
| 42 | } |
| 43 | @@ -420,9 +422,9 @@ exif_data_load_data_content (ExifData *data, ExifIfd ifd, |
| 44 | } |
| 45 | |
| 46 | /* Read the number of entries */ |
| 47 | - if ((offset + 2 < offset) || (offset + 2 < 2) || (offset + 2 > ds)) { |
| 48 | + if (CHECKOVERFLOW(offset, ds, 2)) { |
| 49 | exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA, "ExifData", |
| 50 | - "Tag data past end of buffer (%u > %u)", offset+2, ds); |
| 51 | + "Tag data past end of buffer (%u+2 > %u)", offset, ds); |
| 52 | return; |
| 53 | } |
| 54 | n = exif_get_short (d + offset, data->priv->order); |
| 55 | @@ -431,7 +433,7 @@ exif_data_load_data_content (ExifData *data, ExifIfd ifd, |
| 56 | offset += 2; |
| 57 | |
| 58 | /* Check if we have enough data. */ |
| 59 | - if (offset + 12 * n > ds) { |
| 60 | + if (CHECKOVERFLOW(offset, ds, 12*n)) { |
| 61 | n = (ds - offset) / 12; |
| 62 | exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", |
| 63 | "Short data; only loading %hu entries...", n); |
| 64 | -- |
| 65 | 2.17.1 |
| 66 | |