diff options
Diffstat (limited to 'lib/lz4/lz4_decompress.c')
-rw-r--r-- | lib/lz4/lz4_decompress.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/lz4/lz4_decompress.c b/lib/lz4/lz4_decompress.c index 99a03acb7d47..7a85967060a5 100644 --- a/lib/lz4/lz4_decompress.c +++ b/lib/lz4/lz4_decompress.c | |||
@@ -108,6 +108,8 @@ static int lz4_uncompress(const char *source, char *dest, int osize) | |||
108 | if (length == ML_MASK) { | 108 | if (length == ML_MASK) { |
109 | for (; *ip == 255; length += 255) | 109 | for (; *ip == 255; length += 255) |
110 | ip++; | 110 | ip++; |
111 | if (unlikely(length > (size_t)(length + *ip))) | ||
112 | goto _output_error; | ||
111 | length += *ip++; | 113 | length += *ip++; |
112 | } | 114 | } |
113 | 115 | ||
@@ -157,7 +159,7 @@ static int lz4_uncompress(const char *source, char *dest, int osize) | |||
157 | 159 | ||
158 | /* write overflow error detected */ | 160 | /* write overflow error detected */ |
159 | _output_error: | 161 | _output_error: |
160 | return (int) (-(((char *)ip) - source)); | 162 | return -1; |
161 | } | 163 | } |
162 | 164 | ||
163 | static int lz4_uncompress_unknownoutputsize(const char *source, char *dest, | 165 | static int lz4_uncompress_unknownoutputsize(const char *source, char *dest, |
@@ -190,6 +192,8 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest, | |||
190 | int s = 255; | 192 | int s = 255; |
191 | while ((ip < iend) && (s == 255)) { | 193 | while ((ip < iend) && (s == 255)) { |
192 | s = *ip++; | 194 | s = *ip++; |
195 | if (unlikely(length > (size_t)(length + s))) | ||
196 | goto _output_error; | ||
193 | length += s; | 197 | length += s; |
194 | } | 198 | } |
195 | } | 199 | } |
@@ -230,6 +234,8 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest, | |||
230 | if (length == ML_MASK) { | 234 | if (length == ML_MASK) { |
231 | while (ip < iend) { | 235 | while (ip < iend) { |
232 | int s = *ip++; | 236 | int s = *ip++; |
237 | if (unlikely(length > (size_t)(length + s))) | ||
238 | goto _output_error; | ||
233 | length += s; | 239 | length += s; |
234 | if (s == 255) | 240 | if (s == 255) |
235 | continue; | 241 | continue; |
@@ -282,7 +288,7 @@ static int lz4_uncompress_unknownoutputsize(const char *source, char *dest, | |||
282 | 288 | ||
283 | /* write overflow error detected */ | 289 | /* write overflow error detected */ |
284 | _output_error: | 290 | _output_error: |
285 | return (int) (-(((char *) ip) - source)); | 291 | return -1; |
286 | } | 292 | } |
287 | 293 | ||
288 | int lz4_decompress(const unsigned char *src, size_t *src_len, | 294 | int lz4_decompress(const unsigned char *src, size_t *src_len, |