diff options
author | Josh MacDonald <josh.macdonald@gmail.com> | 2015-11-02 21:33:51 -0800 |
---|---|---|
committer | Josh MacDonald <josh.macdonald@gmail.com> | 2015-11-02 21:33:51 -0800 |
commit | c948e08db789d90547b45ce0a5dcbec9225bad57 (patch) | |
tree | 1fdd31f1fa169a456e8a92b595b3f4d69b3f4c77 /xdelta3 | |
parent | 482c20590f29c91a06430d2818a140257826ac01 (diff) |
Two more invalid input cases [afl]
Diffstat (limited to 'xdelta3')
-rw-r--r-- | xdelta3/xdelta3-decode.h | 11 | ||||
-rw-r--r-- | xdelta3/xdelta3-djw.h | 14 | ||||
-rw-r--r-- | xdelta3/xdelta3-internal.h | 2 | ||||
-rw-r--r-- | xdelta3/xdelta3.c | 29 |
4 files changed, 42 insertions, 14 deletions
diff --git a/xdelta3/xdelta3-decode.h b/xdelta3/xdelta3-decode.h index b44dae4..dc28323 100644 --- a/xdelta3/xdelta3-decode.h +++ b/xdelta3/xdelta3-decode.h | |||
@@ -162,6 +162,9 @@ xd3_decode_allocate (xd3_stream *stream, | |||
162 | uint8_t **buf_ptr, | 162 | uint8_t **buf_ptr, |
163 | usize_t *buf_alloc) | 163 | usize_t *buf_alloc) |
164 | { | 164 | { |
165 | IF_DEBUG2 (DP(RINT "[xd3_decode_allocate] size %u alloc %u\n", | ||
166 | size, *buf_alloc)); | ||
167 | |||
165 | if (*buf_ptr != NULL && *buf_alloc < size) | 168 | if (*buf_ptr != NULL && *buf_alloc < size) |
166 | { | 169 | { |
167 | xd3_free (stream, *buf_ptr); | 170 | xd3_free (stream, *buf_ptr); |
@@ -204,6 +207,9 @@ xd3_decode_section (xd3_stream *stream, | |||
204 | /* No allocation/copy needed */ | 207 | /* No allocation/copy needed */ |
205 | section->buf = stream->next_in; | 208 | section->buf = stream->next_in; |
206 | sect_take = section->size; | 209 | sect_take = section->size; |
210 | |||
211 | IF_DEBUG2 (DP(RINT "[xd3_decode_section] copy==0 @ 0 %u\n", | ||
212 | sect_take, section->alloc1)); | ||
207 | } | 213 | } |
208 | else | 214 | else |
209 | { | 215 | { |
@@ -227,6 +233,11 @@ xd3_decode_section (xd3_stream *stream, | |||
227 | section->buf = section->copied1; | 233 | section->buf = section->copied1; |
228 | } | 234 | } |
229 | 235 | ||
236 | IF_DEBUG2 (DP(RINT "[xd3_decode_section] take %u @ %u[%u] size %u\n", | ||
237 | section->pos, sect_take, section->alloc1, section->size)); | ||
238 | |||
239 | XD3_ASSERT (section->pos + sect_take < section->alloc1); | ||
240 | |||
230 | memcpy (section->copied1 + section->pos, | 241 | memcpy (section->copied1 + section->pos, |
231 | stream->next_in, | 242 | stream->next_in, |
232 | sect_take); | 243 | sect_take); |
diff --git a/xdelta3/xdelta3-djw.h b/xdelta3/xdelta3-djw.h index 080de59..f69cb1d 100644 --- a/xdelta3/xdelta3-djw.h +++ b/xdelta3/xdelta3-djw.h | |||
@@ -1456,7 +1456,7 @@ djw_decode_symbol (xd3_stream *stream, | |||
1456 | if (*input == input_end) | 1456 | if (*input == input_end) |
1457 | { | 1457 | { |
1458 | stream->msg = "secondary decoder end of input"; | 1458 | stream->msg = "secondary decoder end of input"; |
1459 | return XD3_INTERNAL; | 1459 | return XD3_INVALID_INPUT; |
1460 | } | 1460 | } |
1461 | 1461 | ||
1462 | bstate->cur_byte = *(*input)++; | 1462 | bstate->cur_byte = *(*input)++; |
@@ -1479,7 +1479,7 @@ djw_decode_symbol (xd3_stream *stream, | |||
1479 | 1479 | ||
1480 | corrupt: | 1480 | corrupt: |
1481 | stream->msg = "secondary decoder invalid code"; | 1481 | stream->msg = "secondary decoder invalid code"; |
1482 | return XD3_INTERNAL; | 1482 | return XD3_INVALID_INPUT; |
1483 | } | 1483 | } |
1484 | 1484 | ||
1485 | static int | 1485 | static int |
@@ -1606,7 +1606,7 @@ djw_decode_1_2 (xd3_stream *stream, | |||
1606 | if (rep != 0) | 1606 | if (rep != 0) |
1607 | { | 1607 | { |
1608 | stream->msg = "secondary decoder invalid repeat code"; | 1608 | stream->msg = "secondary decoder invalid repeat code"; |
1609 | return XD3_INTERNAL; | 1609 | return XD3_INVALID_INPUT; |
1610 | } | 1610 | } |
1611 | 1611 | ||
1612 | return 0; | 1612 | return 0; |
@@ -1654,7 +1654,7 @@ xd3_decode_huff (xd3_stream *stream, | |||
1654 | if (output_bytes == 0) | 1654 | if (output_bytes == 0) |
1655 | { | 1655 | { |
1656 | stream->msg = "secondary decoder invalid input"; | 1656 | stream->msg = "secondary decoder invalid input"; |
1657 | return XD3_INTERNAL; | 1657 | return XD3_INVALID_INPUT; |
1658 | } | 1658 | } |
1659 | 1659 | ||
1660 | /* Decode: number of groups */ | 1660 | /* Decode: number of groups */ |
@@ -1796,7 +1796,11 @@ xd3_decode_huff (xd3_stream *stream, | |||
1796 | gp_maxlen = maxlen[gp]; | 1796 | gp_maxlen = maxlen[gp]; |
1797 | } | 1797 | } |
1798 | 1798 | ||
1799 | XD3_ASSERT (output_end - output > 0); | 1799 | if (output_end < output) |
1800 | { | ||
1801 | stream->msg = "secondary decoder invalid input"; | ||
1802 | return XD3_INVALID_INPUT; | ||
1803 | } | ||
1800 | 1804 | ||
1801 | /* Decode next sector. */ | 1805 | /* Decode next sector. */ |
1802 | n = xd3_min (sector_size, (usize_t) (output_end - output)); | 1806 | n = xd3_min (sector_size, (usize_t) (output_end - output)); |
diff --git a/xdelta3/xdelta3-internal.h b/xdelta3/xdelta3-internal.h index d6eb0ac..eb360be 100644 --- a/xdelta3/xdelta3-internal.h +++ b/xdelta3/xdelta3-internal.h | |||
@@ -330,12 +330,14 @@ xd3_sizeof_uint64_t (uint64_t num) | |||
330 | 330 | ||
331 | #if SIZEOF_USIZE_T == 4 | 331 | #if SIZEOF_USIZE_T == 4 |
332 | #define USIZE_T_MAX UINT32_MAX | 332 | #define USIZE_T_MAX UINT32_MAX |
333 | #define USIZE_T_MAXBLKSZ 0x80000000U | ||
333 | #define xd3_decode_size xd3_decode_uint32_t | 334 | #define xd3_decode_size xd3_decode_uint32_t |
334 | #define xd3_emit_size xd3_emit_uint32_t | 335 | #define xd3_emit_size xd3_emit_uint32_t |
335 | #define xd3_sizeof_size xd3_sizeof_uint32_t | 336 | #define xd3_sizeof_size xd3_sizeof_uint32_t |
336 | #define xd3_read_size xd3_read_uint32_t | 337 | #define xd3_read_size xd3_read_uint32_t |
337 | #elif SIZEOF_USIZE_T == 8 | 338 | #elif SIZEOF_USIZE_T == 8 |
338 | #define USIZE_T_MAX UINT64_MAX | 339 | #define USIZE_T_MAX UINT64_MAX |
340 | #define USIZE_T_MAXBLKSZ 0x8000000000000000ULL | ||
339 | #define xd3_decode_size xd3_decode_uint64_t | 341 | #define xd3_decode_size xd3_decode_uint64_t |
340 | #define xd3_emit_size xd3_emit_uint64_t | 342 | #define xd3_emit_size xd3_emit_uint64_t |
341 | #define xd3_sizeof_size xd3_sizeof_uint64_t | 343 | #define xd3_sizeof_size xd3_sizeof_uint64_t |
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index 95ff509..51d24de 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c | |||
@@ -1104,7 +1104,17 @@ xd3_round_blksize (usize_t sz, usize_t blksz) | |||
1104 | 1104 | ||
1105 | XD3_ASSERT (xd3_check_pow2 (blksz, NULL) == 0); | 1105 | XD3_ASSERT (xd3_check_pow2 (blksz, NULL) == 0); |
1106 | 1106 | ||
1107 | return mod ? (sz + (blksz - mod)) : sz; | 1107 | if (mod == 0) |
1108 | { | ||
1109 | return sz; | ||
1110 | } | ||
1111 | |||
1112 | if (sz > USIZE_T_MAXBLKSZ) | ||
1113 | { | ||
1114 | return USIZE_T_MAXBLKSZ; | ||
1115 | } | ||
1116 | |||
1117 | return sz + (blksz - mod); | ||
1108 | } | 1118 | } |
1109 | 1119 | ||
1110 | /*********************************************************************** | 1120 | /*********************************************************************** |
@@ -2081,8 +2091,8 @@ xd3_close_stream (xd3_stream *stream) | |||
2081 | break; | 2091 | break; |
2082 | default: | 2092 | default: |
2083 | /* If decoding, should be ready for the next window. */ | 2093 | /* If decoding, should be ready for the next window. */ |
2084 | stream->msg = "EOF in decode"; | 2094 | stream->msg = "eof in decode"; |
2085 | return XD3_INTERNAL; | 2095 | return XD3_INVALID_INPUT; |
2086 | } | 2096 | } |
2087 | } | 2097 | } |
2088 | 2098 | ||
@@ -3762,7 +3772,7 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos) | |||
3762 | frontier_pos, srcpos, stream->src->max_winsize)); | 3772 | frontier_pos, srcpos, stream->src->max_winsize)); |
3763 | if (srcpos < frontier_pos && | 3773 | if (srcpos < frontier_pos && |
3764 | frontier_pos - srcpos > stream->src->max_winsize) { | 3774 | frontier_pos - srcpos > stream->src->max_winsize) { |
3765 | IF_DEBUG1(DP(RINT "[match_setup] rejected due to src->max_winsize " | 3775 | IF_DEBUG2(DP(RINT "[match_setup] rejected due to src->max_winsize " |
3766 | "distance eof=%"Q"u srcpos=%"Q"u maxsz=%"Q"u\n", | 3776 | "distance eof=%"Q"u srcpos=%"Q"u maxsz=%"Q"u\n", |
3767 | xd3_source_eof (stream->src), | 3777 | xd3_source_eof (stream->src), |
3768 | srcpos, stream->src->max_winsize)); | 3778 | srcpos, stream->src->max_winsize)); |
@@ -4423,14 +4433,15 @@ xd3_srcwin_move_point (xd3_stream *stream, usize_t *next_move_point) | |||
4423 | IF_DEBUG1 (DP(RINT | 4433 | IF_DEBUG1 (DP(RINT |
4424 | "[srcwin_move_point] async getblk return for %"Q"u\n", | 4434 | "[srcwin_move_point] async getblk return for %"Q"u\n", |
4425 | blkno)); | 4435 | blkno)); |
4436 | |||
4426 | return ret; | 4437 | return ret; |
4427 | } | 4438 | } |
4428 | 4439 | ||
4429 | IF_DEBUG1 (DP(RINT | 4440 | IF_DEBUG1 (DP(RINT |
4430 | "[srcwin_move_point] T=%"Q"u{%"Q"u} S=%"Q"u EOF=%"Q"u %s\n", | 4441 | "[srcwin_move_point] T=%"Q"u S=%"Q"u L=%"Q"u EOF=%"Q"u %s\n", |
4431 | stream->total_in + stream->input_position, | 4442 | stream->total_in + stream->input_position, |
4432 | logical_input_cksum_pos, | ||
4433 | stream->srcwin_cksum_pos, | 4443 | stream->srcwin_cksum_pos, |
4444 | logical_input_cksum_pos, | ||
4434 | xd3_source_eof (stream->src), | 4445 | xd3_source_eof (stream->src), |
4435 | stream->src->eof_known ? "known" : "unknown")); | 4446 | stream->src->eof_known ? "known" : "unknown")); |
4436 | 4447 | ||
@@ -4475,11 +4486,11 @@ xd3_srcwin_move_point (xd3_stream *stream, usize_t *next_move_point) | |||
4475 | } | 4486 | } |
4476 | 4487 | ||
4477 | IF_DEBUG1 (DP(RINT | 4488 | IF_DEBUG1 (DP(RINT |
4478 | "[srcwin_move_point] exited loop T=%"Q"u{%"Q"u} " | 4489 | "[srcwin_move_point] exited loop T=%"Q"u " |
4479 | "S=%"Q"u EOF=%"Q"u %s\n", | 4490 | "S=%"Q"u L=%"Q" EOF=%"Q"u %s\n", |
4480 | stream->total_in + stream->input_position, | 4491 | stream->total_in + stream->input_position, |
4481 | logical_input_cksum_pos, | ||
4482 | stream->srcwin_cksum_pos, | 4492 | stream->srcwin_cksum_pos, |
4493 | logical_input_cksum_pos, | ||
4483 | xd3_source_eof (stream->src), | 4494 | xd3_source_eof (stream->src), |
4484 | stream->src->eof_known ? "known" : "unknown")); | 4495 | stream->src->eof_known ? "known" : "unknown")); |
4485 | 4496 | ||