Line 0
Link Here
|
|
|
1 |
https://github.com/libexif/libexif/commit/75aa73267fdb1e0ebfbc00369e7312bac43d0566.patch |
2 |
From 75aa73267fdb1e0ebfbc00369e7312bac43d0566 Mon Sep 17 00:00:00 2001 |
3 |
From: Marcus Meissner <meissner@suse.de> |
4 |
Date: Sat, 18 Jan 2020 09:29:42 +0100 |
5 |
Subject: [PATCH] fix CVE-2019-9278 |
6 |
|
7 |
avoid the use of unsafe integer overflow checking constructs (unsigned integer operations cannot overflow, so "u1 + u2 > u1" can be optimized away) |
8 |
|
9 |
check for the actual sizes, which should also handle the overflows |
10 |
document other places google patched, but do not seem relevant due to other restrictions |
11 |
|
12 |
fixes https://github.com/libexif/libexif/issues/26 |
13 |
--- |
14 |
libexif/exif-data.c | 28 ++++++++++++++++++---------- |
15 |
1 file changed, 18 insertions(+), 10 deletions(-) |
16 |
|
17 |
diff --git libexif/exif-data.c libexif/exif-data.c |
18 |
index a6f9c94..6332cd1 100644 |
19 |
--- libexif/exif-data.c |
20 |
+++ libexif/exif-data.c |
21 |
@@ -192,9 +192,15 @@ exif_data_load_data_entry (ExifData *data, ExifEntry *entry, |
22 |
doff = offset + 8; |
23 |
|
24 |
/* Sanity checks */ |
25 |
- if ((doff + s < doff) || (doff + s < s) || (doff + s > size)) { |
26 |
+ if (doff >= size) { |
27 |
exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", |
28 |
- "Tag data past end of buffer (%u > %u)", doff+s, size); |
29 |
+ "Tag starts past end of buffer (%u > %u)", doff, size); |
30 |
+ return 0; |
31 |
+ } |
32 |
+ |
33 |
+ if (s > size - doff) { |
34 |
+ exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", |
35 |
+ "Tag data goes past end of buffer (%u > %u)", doff+s, size); |
36 |
return 0; |
37 |
} |
38 |
|
39 |
@@ -315,13 +321,14 @@ exif_data_load_data_thumbnail (ExifData *data, const unsigned char *d, |
40 |
unsigned int ds, ExifLong o, ExifLong s) |
41 |
{ |
42 |
/* Sanity checks */ |
43 |
- if ((o + s < o) || (o + s < s) || (o + s > ds) || (o > ds)) { |
44 |
- exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", |
45 |
- "Bogus thumbnail offset (%u) or size (%u).", |
46 |
- o, s); |
47 |
+ if (o >= ds) { |
48 |
+ exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", "Bogus thumbnail offset (%u).", o); |
49 |
+ return; |
50 |
+ } |
51 |
+ if (s > ds - o) { |
52 |
+ exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", "Bogus thumbnail size (%u), max would be %u.", s, ds-o); |
53 |
return; |
54 |
} |
55 |
- |
56 |
if (data->data) |
57 |
exif_mem_free (data->priv->mem, data->data); |
58 |
if (!(data->data = exif_data_alloc (data, s))) { |
59 |
@@ -947,7 +954,7 @@ exif_data_load_data (ExifData *data, const unsigned char *d_orig, |
60 |
exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", |
61 |
"IFD 0 at %i.", (int) offset); |
62 |
|
63 |
- /* Sanity check the offset, being careful about overflow */ |
64 |
+ /* ds is restricted to 16 bit above, so offset is restricted too, and offset+8 should not overflow. */ |
65 |
if (offset > ds || offset + 6 + 2 > ds) |
66 |
return; |
67 |
|
68 |
@@ -956,6 +963,7 @@ exif_data_load_data (ExifData *data, const unsigned char *d_orig, |
69 |
|
70 |
/* IFD 1 offset */ |
71 |
n = exif_get_short (d + 6 + offset, data->priv->order); |
72 |
+ /* offset < 2<<16, n is 16 bit at most, so this op will not overflow */ |
73 |
if (offset + 6 + 2 + 12 * n + 4 > ds) |
74 |
return; |
75 |
|
76 |
@@ -964,8 +972,8 @@ exif_data_load_data (ExifData *data, const unsigned char *d_orig, |
77 |
exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", |
78 |
"IFD 1 at %i.", (int) offset); |
79 |
|
80 |
- /* Sanity check. */ |
81 |
- if (offset > ds || offset + 6 > ds) { |
82 |
+ /* Sanity check. ds is ensured to be above 6 above, offset is 16bit */ |
83 |
+ if (offset > ds - 6) { |
84 |
exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA, |
85 |
"ExifData", "Bogus offset of IFD1."); |
86 |
} else { |