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