diff options
Diffstat (limited to 'xdelta3/xdelta3.c')
-rw-r--r-- | xdelta3/xdelta3.c | 133 |
1 files changed, 101 insertions, 32 deletions
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index 5f52ad9..b8aa9eb 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c | |||
@@ -535,7 +535,7 @@ static void xd3_verify_run_state (xd3_stream *stream, | |||
535 | uint8_t *x_run_c); | 535 | uint8_t *x_run_c); |
536 | static void xd3_verify_large_state (xd3_stream *stream, | 536 | static void xd3_verify_large_state (xd3_stream *stream, |
537 | const uint8_t *inp, | 537 | const uint8_t *inp, |
538 | uint32_t x_cksum); | 538 | usize_t x_cksum); |
539 | static void xd3_verify_small_state (xd3_stream *stream, | 539 | static void xd3_verify_small_state (xd3_stream *stream, |
540 | const uint8_t *inp, | 540 | const uint8_t *inp, |
541 | uint32_t x_cksum); | 541 | uint32_t x_cksum); |
@@ -567,17 +567,17 @@ static int xd3_selftest (void); | |||
567 | #define UINT64_OFLOW_MASK 0xfe00000000000000ULL | 567 | #define UINT64_OFLOW_MASK 0xfe00000000000000ULL |
568 | 568 | ||
569 | #if SIZEOF_USIZE_T == 4 | 569 | #if SIZEOF_USIZE_T == 4 |
570 | #define USIZE_T_MAX UINT32_MAX | 570 | #define USIZE_T_MAX UINT32_MAX |
571 | #define xd3_decode_size xd3_decode_uint32_t | 571 | #define xd3_decode_size xd3_decode_uint32_t |
572 | #define xd3_emit_size xd3_emit_uint32_t | 572 | #define xd3_emit_size xd3_emit_uint32_t |
573 | #define xd3_sizeof_size xd3_sizeof_uint32_t | 573 | #define xd3_sizeof_size xd3_sizeof_uint32_t |
574 | #define xd3_read_size xd3_read_uint32_t | 574 | #define xd3_read_size xd3_read_uint32_t |
575 | #elif SIZEOF_USIZE_T == 8 | 575 | #elif SIZEOF_USIZE_T == 8 |
576 | #define USIZE_T_MAX UINT64_MAX | 576 | #define USIZE_T_MAX UINT64_MAX |
577 | #define xd3_decode_size xd3_decode_uint64_t | 577 | #define xd3_decode_size xd3_decode_uint64_t |
578 | #define xd3_emit_size xd3_emit_uint64_t | 578 | #define xd3_emit_size xd3_emit_uint64_t |
579 | #define xd3_sizeof_size xd3_sizeof_uint64_t | 579 | #define xd3_sizeof_size xd3_sizeof_uint64_t |
580 | #define xd3_read_size xd3_read_uint64_t | 580 | #define xd3_read_size xd3_read_uint64_t |
581 | #endif | 581 | #endif |
582 | 582 | ||
583 | #if SIZEOF_XOFF_T == 4 | 583 | #if SIZEOF_XOFF_T == 4 |
@@ -798,10 +798,9 @@ const xd3_sec_type lzma_sec_type = | |||
798 | #endif /* __XDELTA3_C_HEADER_PASS__ */ | 798 | #endif /* __XDELTA3_C_HEADER_PASS__ */ |
799 | #ifdef __XDELTA3_C_INLINE_PASS__ | 799 | #ifdef __XDELTA3_C_INLINE_PASS__ |
800 | 800 | ||
801 | const uint16_t __single_hash[256] = | 801 | const uint16_t __single_hash32[256] = |
802 | { | 802 | { |
803 | /* Random numbers generated using SLIB's pseudo-random number generator. | 803 | /* This hashes the input alphabet (Scheme SLIB pseudo-random). */ |
804 | * This hashes the input alphabet. */ | ||
805 | 0xbcd1, 0xbb65, 0x42c2, 0xdffe, 0x9666, 0x431b, 0x8504, 0xeb46, | 804 | 0xbcd1, 0xbb65, 0x42c2, 0xdffe, 0x9666, 0x431b, 0x8504, 0xeb46, |
806 | 0x6379, 0xd460, 0xcf14, 0x53cf, 0xdb51, 0xdb08, 0x12c8, 0xf602, | 805 | 0x6379, 0xd460, 0xcf14, 0x53cf, 0xdb51, 0xdb08, 0x12c8, 0xf602, |
807 | 0xe766, 0x2394, 0x250d, 0xdcbb, 0xa678, 0x02af, 0xa5c6, 0x7ea6, | 806 | 0xe766, 0x2394, 0x250d, 0xdcbb, 0xa678, 0x02af, 0xa5c6, 0x7ea6, |
@@ -836,6 +835,75 @@ const uint16_t __single_hash[256] = | |||
836 | 0x1672, 0xec28, 0x6acb, 0x86cc, 0x186e, 0x9414, 0xd674, 0xd1a5 | 835 | 0x1672, 0xec28, 0x6acb, 0x86cc, 0x186e, 0x9414, 0xd674, 0xd1a5 |
837 | }; | 836 | }; |
838 | 837 | ||
838 | const uint32_t __single_hash64[256] = | ||
839 | { | ||
840 | /* http://random.org 2014.10.24 */ | ||
841 | 0xd25e9f0a, 0xb1af9d5e, 0xb753dfa2, 0x157050f7, /* 0 */ | ||
842 | 0xc84b072c, 0xdd14fe7c, 0xf92208c3, 0xdf08a0c0, | ||
843 | 0x63a5c118, 0x76f5d90f, 0xa2f8b93e, 0xb6c12d22, | ||
844 | 0xaf074957, 0x966fb7d9, 0x62f7b785, 0xb40e8a09, | ||
845 | 0x0a811d5d, 0x323a6daa, 0xb62f7c5b, 0xfdcb9a53, | ||
846 | 0xf25a9067, 0x4506bc7a, 0xff58a74b, 0x5ae62817, | ||
847 | 0x74097675, 0x722c0fd9, 0x116a2a66, 0x65f76728, | ||
848 | 0x72c79651, 0xe043cf9d, 0x64b867c7, 0x6604834f, | ||
849 | 0xcdca58a6, 0x0f164e2d, 0x24515f05, 0x632cdbf8, | ||
850 | 0x18091d4a, 0x3eff4128, 0x673d1c33, 0xd8e10c71, | ||
851 | 0x1a3edf11, 0xba52892f, 0xa56949e0, 0xf3e1dd77, /* 10 */ | ||
852 | 0x86fcbe3e, 0x138d66d0, 0x4fc98359, 0xc22e5dd6, | ||
853 | 0xc59f2267, 0x6c6dd739, 0xe03da190, 0x07e8469c, | ||
854 | 0xadcfb02c, 0x00d3b0d9, 0xa1f44918, 0x8bd84d87, | ||
855 | 0x08ec9ec1, 0xbbcd156f, 0xb57718e3, 0x3177e752, | ||
856 | 0xf52a4d70, 0xde7aaad9, 0x075f1da0, 0x21ba00c6, | ||
857 | 0xb9469a5c, 0xcf08d5ba, 0x91ac9edc, 0xc6167b63, | ||
858 | 0xc1974919, 0xc8c8d195, 0x4b1996dd, 0xeff8991c, | ||
859 | 0xf7f66c6b, 0x25b012e2, 0x59d12a98, 0xea40d3cc, | ||
860 | 0x41f9970b, 0xec48101a, 0xa3bdcf90, 0x99f16905, | ||
861 | 0x27af6c97, 0xc849af37, 0x49cad89b, 0xf48c2278, /* 20 */ | ||
862 | 0x5529c3d8, 0x9e7d6dce, 0x16feb52d, 0xf1b0aca1, | ||
863 | 0xaf28fccb, 0x48e4ce3c, 0xc4436617, 0x64524e3e, | ||
864 | 0x61806681, 0x6384f2d7, 0x1172880f, 0x34a5ef5f, | ||
865 | 0xcc8cc0a8, 0x66e8f100, 0x2866085f, 0xba9b1b2d, | ||
866 | 0x51285949, 0x2be4b574, 0x889b1ef5, 0x3dbe920d, | ||
867 | 0x9277a62f, 0x0584a9f6, 0x085d8fc4, 0x4b5d403d, | ||
868 | 0x4e46ca78, 0x3294c2f9, 0x29313e70, 0xe4f09b24, | ||
869 | 0xe73b331c, 0x072f5552, 0x2e390b78, 0xea0021ca, | ||
870 | 0xd8f40320, 0xed0e16fd, 0x7de9cf7a, 0xf17e3d6c, | ||
871 | 0x8df1bd85, 0x052cae67, 0x3486e512, 0x3a1c09b8, /* 30 */ | ||
872 | 0x6c2a7b4e, 0x83455753, 0xbc0353ac, 0x0ffe20b6, | ||
873 | 0x5fdcef85, 0x010f506c, 0x595ce972, 0xe28680d0, | ||
874 | 0xa7e216b2, 0xa392ee0f, 0x25b73faa, 0x2b1f4983, | ||
875 | 0xeeaefe98, 0x1d3d9cbc, 0x6aebe97b, 0x8b7b3584, | ||
876 | 0x9e6a9a07, 0xd37f1e99, 0x4ac2a441, 0x8ae9a213, | ||
877 | 0x7d0e27d7, 0x5de54b9a, 0x8621de1f, 0xf0f2f866, | ||
878 | 0xcb08d275, 0x49c3f87e, 0xd5ee68c1, 0x9802fc77, | ||
879 | 0x68be6c5e, 0x65aa8c27, 0xf423d5f7, 0x10ec5502, | ||
880 | 0x9909bce1, 0x509cdf1b, 0x338fea72, 0x2733e9bf, | ||
881 | 0xf92f4fd7, 0x87738ea2, 0x931a8bbc, 0x0a5c9155, /* 40 */ | ||
882 | 0xbe5edd9b, 0xadbf5838, 0x0338f8d2, 0x290da210, | ||
883 | 0x390c37d8, 0xe7cffae8, 0x20617ebe, 0x464322dd, | ||
884 | 0x7b3c4e78, 0xac142dcb, 0x2d5cef76, 0xd8fe49fc, | ||
885 | 0x60f4e9a9, 0x7473816f, 0x0dc35f39, 0x5eed80c1, | ||
886 | 0x0cb55ab6, 0x1d3ac541, 0x13c7f529, 0x7bffdf4a, | ||
887 | 0xe334785b, 0x85263ec1, 0xd132ae56, 0x7c868b9e, | ||
888 | 0x47f60638, 0x1012b979, 0x81c31dd3, 0x1af868c8, | ||
889 | 0x0c5d0742, 0xd1b3e1a2, 0x5873200a, 0xf848465c, | ||
890 | 0x0fc4d596, 0x609c18af, 0xc9f5a480, 0xd1a94a84, | ||
891 | 0xa1431a3f, 0x7de8bb1a, 0x25f1256b, 0x1dcc732c, /* 50 */ | ||
892 | 0x6aa1549a, 0xa2367281, 0x32f2a77e, 0x82e62a0f, | ||
893 | 0x045cbb56, 0x74b2027c, 0xd71a32d9, 0x022e7cb5, | ||
894 | 0xe99be177, 0x60222fdf, 0xd69681ca, 0x9008ee2c, | ||
895 | 0x32923db4, 0xcf82bf97, 0x38960a5b, 0xb3503d5b, | ||
896 | 0x9bd4c7f2, 0x33c029c8, 0x1ef504a3, 0xdb249d3b, | ||
897 | 0x91e89676, 0x4ca43b36, 0x9191433c, 0x465d5dc4, | ||
898 | 0xf4dcb118, 0x9d11dd00, 0xb592f058, 0xdbe5ce30, | ||
899 | 0x74790d92, 0x779850a8, 0x7180d25b, 0xfa951d99, | ||
900 | 0x5990935a, 0x921cb022, 0x3b7c39bc, 0x6a38a7c7, | ||
901 | 0xdc22703b, 0x142bab3b, 0x4e3d9479, 0x44bb8482, /* 60 */ | ||
902 | 0x8043abce, 0xfebe832a, 0x8e6a2f98, 0x4d43c4fe, | ||
903 | 0xd192a70a, 0x802f3c3a, 0x5d11bbab, 0x2665d241, | ||
904 | 0xb3f3a680, 0x3a8d223f, 0xcf82cdb4, 0x4ed28743, | ||
905 | }; | ||
906 | |||
839 | /**************************************************************** | 907 | /**************************************************************** |
840 | Instruction tables | 908 | Instruction tables |
841 | *****************************************************************/ | 909 | *****************************************************************/ |
@@ -952,7 +1020,7 @@ xd3_build_code_table (const xd3_code_table_desc *desc, xd3_dinst *tbl) | |||
952 | { | 1020 | { |
953 | uint8_t size1, size2; | 1021 | uint8_t size1, size2; |
954 | uint8_t mode; | 1022 | uint8_t mode; |
955 | usize_t cpy_modes = 2 + desc->near_modes + desc->same_modes; | 1023 | usize_t cpy_modes = 2U + desc->near_modes + desc->same_modes; |
956 | xd3_dinst *d = tbl; | 1024 | xd3_dinst *d = tbl; |
957 | 1025 | ||
958 | (d++)->type1 = XD3_RUN; | 1026 | (d++)->type1 = XD3_RUN; |
@@ -968,7 +1036,7 @@ xd3_build_code_table (const xd3_code_table_desc *desc, xd3_dinst *tbl) | |||
968 | { | 1036 | { |
969 | (d++)->type1 = XD3_CPY + mode; | 1037 | (d++)->type1 = XD3_CPY + mode; |
970 | 1038 | ||
971 | for (size1 = MIN_MATCH; size1 < MIN_MATCH + desc->cpy_sizes; | 1039 | for (size1 = MIN_MATCH; size1 < MIN_MATCH + desc->cpy_sizes; |
972 | size1 += 1, d += 1) | 1040 | size1 += 1, d += 1) |
973 | { | 1041 | { |
974 | d->type1 = XD3_CPY + mode; | 1042 | d->type1 = XD3_CPY + mode; |
@@ -1078,8 +1146,8 @@ xd3_choose_instruction (xd3_rinst *prev, xd3_rinst *inst) | |||
1078 | if ( (inst->size <= 6) && | 1146 | if ( (inst->size <= 6) && |
1079 | (mode <= 5) ) | 1147 | (mode <= 5) ) |
1080 | { | 1148 | { |
1081 | prev->code2 = (uint8_t)(163 + (mode * 12) + | 1149 | prev->code2 = (uint8_t)(163 + (mode * 12) + |
1082 | (3 * (prev->size - 1)) + | 1150 | (3 * (prev->size - 1)) + |
1083 | (inst->size - 4)); | 1151 | (inst->size - 4)); |
1084 | XD3_ASSERT (prev->code2 <= 234); | 1152 | XD3_ASSERT (prev->code2 <= 234); |
1085 | } | 1153 | } |
@@ -1358,10 +1426,10 @@ xd3_emit_bytes (xd3_stream *stream, | |||
1358 | Integer encoder/decoder functions | 1426 | Integer encoder/decoder functions |
1359 | **********************************************************************/ | 1427 | **********************************************************************/ |
1360 | 1428 | ||
1361 | #define DECODE_INTEGER_TYPE(PART,OFLOW) \ | 1429 | #define DECODE_INTEGER_TYPE(TYPE,PART,OFLOW) \ |
1362 | while (stream->avail_in != 0) \ | 1430 | while (stream->avail_in != 0) \ |
1363 | { \ | 1431 | { \ |
1364 | usize_t next = stream->next_in[0]; \ | 1432 | TYPE next = stream->next_in[0]; \ |
1365 | \ | 1433 | \ |
1366 | DECODE_INPUT(1); \ | 1434 | DECODE_INPUT(1); \ |
1367 | \ | 1435 | \ |
@@ -1386,8 +1454,8 @@ xd3_emit_bytes (xd3_stream *stream, | |||
1386 | 1454 | ||
1387 | #define READ_INTEGER_TYPE(TYPE, OFLOW) \ | 1455 | #define READ_INTEGER_TYPE(TYPE, OFLOW) \ |
1388 | TYPE val = 0; \ | 1456 | TYPE val = 0; \ |
1457 | TYPE next; \ | ||
1389 | const uint8_t *inp = (*inpp); \ | 1458 | const uint8_t *inp = (*inpp); \ |
1390 | usize_t next; \ | ||
1391 | \ | 1459 | \ |
1392 | do \ | 1460 | do \ |
1393 | { \ | 1461 | { \ |
@@ -1447,7 +1515,7 @@ xd3_sizeof_uint32_t (uint32_t num) | |||
1447 | 1515 | ||
1448 | int | 1516 | int |
1449 | xd3_decode_uint32_t (xd3_stream *stream, uint32_t *val) | 1517 | xd3_decode_uint32_t (xd3_stream *stream, uint32_t *val) |
1450 | { DECODE_INTEGER_TYPE (stream->dec_32part, UINT32_OFLOW_MASK); } | 1518 | { DECODE_INTEGER_TYPE (uint32_t, stream->dec_32part, UINT32_OFLOW_MASK); } |
1451 | 1519 | ||
1452 | int | 1520 | int |
1453 | xd3_read_uint32_t (xd3_stream *stream, const uint8_t **inpp, | 1521 | xd3_read_uint32_t (xd3_stream *stream, const uint8_t **inpp, |
@@ -1464,7 +1532,7 @@ xd3_emit_uint32_t (xd3_stream *stream, xd3_output **output, uint32_t num) | |||
1464 | #if USE_UINT64 | 1532 | #if USE_UINT64 |
1465 | int | 1533 | int |
1466 | xd3_decode_uint64_t (xd3_stream *stream, uint64_t *val) | 1534 | xd3_decode_uint64_t (xd3_stream *stream, uint64_t *val) |
1467 | { DECODE_INTEGER_TYPE (stream->dec_64part, UINT64_OFLOW_MASK); } | 1535 | { DECODE_INTEGER_TYPE (uint64_t, stream->dec_64part, UINT64_OFLOW_MASK); } |
1468 | 1536 | ||
1469 | #if XD3_ENCODER | 1537 | #if XD3_ENCODER |
1470 | int | 1538 | int |
@@ -2525,7 +2593,8 @@ xd3_iopt_finish_encoding (xd3_stream *stream, xd3_rinst *inst) | |||
2525 | { | 2593 | { |
2526 | if (stream->iout->code2 != 0) | 2594 | if (stream->iout->code2 != 0) |
2527 | { | 2595 | { |
2528 | if ((ret = xd3_emit_double (stream, stream->iout, inst, stream->iout->code2))) { return ret; } | 2596 | if ((ret = xd3_emit_double (stream, stream->iout, inst, |
2597 | stream->iout->code2))) { return ret; } | ||
2529 | 2598 | ||
2530 | xd3_iopt_free_nonadd (stream, stream->iout); | 2599 | xd3_iopt_free_nonadd (stream, stream->iout); |
2531 | xd3_iopt_free_nonadd (stream, inst); | 2600 | xd3_iopt_free_nonadd (stream, inst); |
@@ -3612,7 +3681,7 @@ xd3_process_stream (int is_encode, | |||
3612 | case XD3_OUTPUT: { /* memcpy below */ break; } | 3681 | case XD3_OUTPUT: { /* memcpy below */ break; } |
3613 | case XD3_INPUT: { | 3682 | case XD3_INPUT: { |
3614 | n = min(stream->winsize, input_size - ipos); | 3683 | n = min(stream->winsize, input_size - ipos); |
3615 | if (n == 0) | 3684 | if (n == 0) |
3616 | { | 3685 | { |
3617 | goto done; | 3686 | goto done; |
3618 | } | 3687 | } |
@@ -3948,13 +4017,13 @@ xd3_srcwin_setup (xd3_stream *stream) | |||
3948 | 4017 | ||
3949 | if (src->eof_known) | 4018 | if (src->eof_known) |
3950 | { | 4019 | { |
3951 | /* Note: if the source size is known, we must reduce srclen or | 4020 | /* Note: if the source size is known, we must reduce srclen or |
3952 | * code that expects to pass a single block w/ getblk == NULL | 4021 | * code that expects to pass a single block w/ getblk == NULL |
3953 | * will not function, as the code will return GETSRCBLK asking | 4022 | * will not function, as the code will return GETSRCBLK asking |
3954 | * for the second block. */ | 4023 | * for the second block. */ |
3955 | src->srclen = min (src->srclen, xd3_source_eof(src) - src->srcbase); | 4024 | src->srclen = min (src->srclen, xd3_source_eof(src) - src->srcbase); |
3956 | } | 4025 | } |
3957 | 4026 | ||
3958 | IF_DEBUG1 (DP(RINT "[srcwin_setup_constrained] base %llu len %llu\n", | 4027 | IF_DEBUG1 (DP(RINT "[srcwin_setup_constrained] base %llu len %llu\n", |
3959 | src->srcbase, src->srclen)); | 4028 | src->srcbase, src->srclen)); |
3960 | 4029 | ||
@@ -4545,7 +4614,7 @@ xd3_smatch (xd3_stream *stream, | |||
4545 | static void | 4614 | static void |
4546 | xd3_verify_small_state (xd3_stream *stream, | 4615 | xd3_verify_small_state (xd3_stream *stream, |
4547 | const uint8_t *inp, | 4616 | const uint8_t *inp, |
4548 | uint32_t x_cksum) | 4617 | uint32_t x_cksum) |
4549 | { | 4618 | { |
4550 | uint32_t state; | 4619 | uint32_t state; |
4551 | uint32_t cksum = xd3_scksum (&state, inp, stream->smatcher.small_look); | 4620 | uint32_t cksum = xd3_scksum (&state, inp, stream->smatcher.small_look); |
@@ -4556,9 +4625,9 @@ xd3_verify_small_state (xd3_stream *stream, | |||
4556 | static void | 4625 | static void |
4557 | xd3_verify_large_state (xd3_stream *stream, | 4626 | xd3_verify_large_state (xd3_stream *stream, |
4558 | const uint8_t *inp, | 4627 | const uint8_t *inp, |
4559 | uint32_t x_cksum) | 4628 | usize_t x_cksum) |
4560 | { | 4629 | { |
4561 | uint32_t cksum = xd3_large_cksum (inp, stream->smatcher.large_look); | 4630 | usize_t cksum = xd3_large_cksum (inp, stream->smatcher.large_look); |
4562 | XD3_ASSERT (cksum == x_cksum); | 4631 | XD3_ASSERT (cksum == x_cksum); |
4563 | } | 4632 | } |
4564 | static void | 4633 | static void |
@@ -4702,7 +4771,7 @@ xd3_srcwin_move_point (xd3_stream *stream, usize_t *next_move_point) | |||
4702 | 4771 | ||
4703 | do | 4772 | do |
4704 | { | 4773 | { |
4705 | uint32_t cksum = xd3_large_cksum (stream->src->curblk + blkpos, | 4774 | usize_t cksum = xd3_large_cksum (stream->src->curblk + blkpos, |
4706 | stream->smatcher.large_look); | 4775 | stream->smatcher.large_look); |
4707 | usize_t hval = xd3_checksum_hash (& stream->large_hash, cksum); | 4776 | usize_t hval = xd3_checksum_hash (& stream->large_hash, cksum); |
4708 | 4777 | ||
@@ -4795,7 +4864,7 @@ XD3_TEMPLATE(xd3_string_match_) (xd3_stream *stream) | |||
4795 | const uint8_t *inp; | 4864 | const uint8_t *inp; |
4796 | uint32_t scksum = 0; | 4865 | uint32_t scksum = 0; |
4797 | uint32_t scksum_state = 0; | 4866 | uint32_t scksum_state = 0; |
4798 | uint32_t lcksum = 0; | 4867 | usize_t lcksum = 0; |
4799 | usize_t sinx; | 4868 | usize_t sinx; |
4800 | usize_t linx; | 4869 | usize_t linx; |
4801 | uint8_t run_c; | 4870 | uint8_t run_c; |