diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-08 13:35:28 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-08 13:35:28 +0200 |
commit | 3a7d16d48885cf880cf404ef23f5fc48c1d1dc6a (patch) | |
tree | 9c50051bd5baf582937ec3b7010dd96023df6dbf | |
parent | 434f95960ad484d09ce0cad5dbf44b11312963f8 (diff) | |
download | busybox-w32-3a7d16d48885cf880cf404ef23f5fc48c1d1dc6a.tar.gz busybox-w32-3a7d16d48885cf880cf404ef23f5fc48c1d1dc6a.tar.bz2 busybox-w32-3a7d16d48885cf880cf404ef23f5fc48c1d1dc6a.zip |
lzop: don't support ancient versions < 0.94 (15 Oct 1997)
0.94 came only 2 months after initial 0.90:
0.90 (10 Aug 1997): First public release of lzop
...
0.94 (15 Oct 1997): Header format change
function old new delta
do_lzo_decompress 411 404 -7
f_read8 24 - -24
f_read16 31 - -31
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/1 up/down: 0/-62) Total: -62 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/lzop.c | 101 |
1 files changed, 49 insertions, 52 deletions
diff --git a/archival/lzop.c b/archival/lzop.c index 419e1e21f..e724b9edf 100644 --- a/archival/lzop.c +++ b/archival/lzop.c | |||
@@ -448,7 +448,7 @@ typedef struct header_t { | |||
448 | uint16_t version_needed_to_extract_be16; | 448 | uint16_t version_needed_to_extract_be16; |
449 | uint8_t method; | 449 | uint8_t method; |
450 | uint8_t level; | 450 | uint8_t level; |
451 | uint32_t flags32; /* be32 on disk, but we keep them in native order */ | 451 | uint32_t flags32; /* be32 on disk, but we keep this field in native order */ |
452 | uint32_t mode_be32; | 452 | uint32_t mode_be32; |
453 | uint32_t mtime_be32; | 453 | uint32_t mtime_be32; |
454 | uint32_t gmtdiff_be32; | 454 | uint32_t gmtdiff_be32; |
@@ -577,18 +577,18 @@ static void f_read(void* buf, int cnt) | |||
577 | xread(0, buf, cnt); | 577 | xread(0, buf, cnt); |
578 | add_bytes_to_chksum(buf, cnt); | 578 | add_bytes_to_chksum(buf, cnt); |
579 | } | 579 | } |
580 | static int f_read8(void) | 580 | //static int f_read8(void) |
581 | { | 581 | //{ |
582 | uint8_t v; | 582 | // uint8_t v; |
583 | f_read(&v, 1); | 583 | // f_read(&v, 1); |
584 | return v; | 584 | // return v; |
585 | } | 585 | //} |
586 | static unsigned f_read16(void) | 586 | //static unsigned f_read16(void) |
587 | { | 587 | //{ |
588 | uint16_t v; | 588 | // uint16_t v; |
589 | f_read(&v, 2); | 589 | // f_read(&v, 2); |
590 | return ntohs(v); | 590 | // return ntohs(v); |
591 | } | 591 | //} |
592 | static uint32_t f_read32(void) | 592 | static uint32_t f_read32(void) |
593 | { | 593 | { |
594 | uint32_t v; | 594 | uint32_t v; |
@@ -928,66 +928,62 @@ static int read_header(header_t *h) | |||
928 | { | 928 | { |
929 | int l; | 929 | int l; |
930 | uint32_t checksum; | 930 | uint32_t checksum; |
931 | /* As it stands now, only h->flags32 is used by our caller. | ||
932 | * Therefore we don't store many fields in h->FIELD. | ||
933 | */ | ||
931 | unsigned h_version; | 934 | unsigned h_version; |
932 | uint8_t h_method, h_level; | 935 | unsigned h_version_needed_to_extract; |
933 | 936 | ||
934 | init_chksum(); | 937 | init_chksum(); |
935 | 938 | ||
936 | /* As it stands now, only h->flags32 is used by our caller. | 939 | /* We don't support versions < 0.94, since 0.94 |
937 | * Therefore we don't store many fields in h->field. | 940 | * came only 2 months after 0.90: |
941 | * 0.90 (10 Aug 1997): First public release of lzop | ||
942 | * 0.94 (15 Oct 1997): Header format change | ||
938 | */ | 943 | */ |
939 | h_version = f_read16(); | 944 | |
940 | if (h_version < 0x0900) | 945 | /* Read up to and including name length byte */ |
946 | f_read(&h->version_be16, ((char*)&h->len_and_name[1]) - ((char*)&h->version_be16)); | ||
947 | |||
948 | h_version = htons(h->version_be16); | ||
949 | if (h_version < 0x0940) | ||
950 | return 3; | ||
951 | h_version_needed_to_extract = htons(h->version_needed_to_extract_be16); | ||
952 | if (h_version_needed_to_extract > LZOP_VERSION) | ||
953 | return 16; | ||
954 | if (h_version_needed_to_extract < 0x0940) | ||
941 | return 3; | 955 | return 3; |
942 | /* UNUSED h->lib_version_be16 = */ f_read16(); | ||
943 | if (h_version >= 0x0940) { | ||
944 | unsigned h_version_needed_to_extract = f_read16(); | ||
945 | if (h_version_needed_to_extract > LZOP_VERSION) | ||
946 | return 16; | ||
947 | if (h_version_needed_to_extract < 0x0900) /* first lzop version */ | ||
948 | return 3; | ||
949 | } | ||
950 | 956 | ||
951 | h_method = f_read8(); | 957 | if (h->method <= 0) |
952 | if (h_method <= 0) | ||
953 | return 14; | 958 | return 14; |
954 | h_level = 0; | ||
955 | if (h_version >= 0x0940) | ||
956 | h_level = f_read8(); | ||
957 | 959 | ||
958 | /* former lzo_get_method(h): */ | 960 | /* former lzo_get_method(h): */ |
959 | if (h_method == M_LZO1X_1) { | 961 | if (h->method == M_LZO1X_1) { |
960 | if (h_level == 0) | 962 | if (h->level == 0) |
961 | h_level = 3; | 963 | h->level = 3; |
962 | } else if (h_method == M_LZO1X_1_15) { | 964 | } else if (h->method == M_LZO1X_1_15) { |
963 | if (h_level == 0) | 965 | if (h->level == 0) |
964 | h_level = 1; | 966 | h->level = 1; |
965 | } else if (h_method == M_LZO1X_999) { | 967 | } else if (h->method == M_LZO1X_999) { |
966 | if (h_level == 0) | 968 | if (h->level == 0) |
967 | h_level = 9; | 969 | h->level = 9; |
968 | } else | 970 | } else |
969 | return -1; /* not a LZO method */ | 971 | return -1; /* not a LZO method */ |
970 | /* check compression level */ | 972 | /* check compression level */ |
971 | if (h_level < 1 || h_level > 9) | 973 | if (h->level < 1 || h->level > 9) |
972 | return 15; | 974 | return 15; |
973 | 975 | ||
974 | h->flags32 = f_read32(); | 976 | h->flags32 = ntohl(h->flags32); |
975 | if (h->flags32 & F_H_FILTER) | 977 | if (h->flags32 & F_H_FILTER) |
976 | return 16; /* filter not supported */ | 978 | return 16; /* filter not supported */ |
977 | /* check reserved flags */ | 979 | /* check reserved flags */ |
978 | if (h->flags32 & F_RESERVED) | 980 | if (h->flags32 & F_RESERVED) |
979 | return -13; | 981 | return -13; |
980 | 982 | ||
981 | /* UNUSED h->mode = */ f_read32(); | 983 | l = h->len_and_name[0]; |
982 | /* UNUSED h->mtime = */ f_read32(); | ||
983 | if (h_version >= 0x0940) | ||
984 | /* UNUSED h->gmtdiff = */ f_read32(); | ||
985 | |||
986 | l = f_read8(); | ||
987 | /* UNUSED h->len_and_name[0] = l; */ | ||
988 | /* UNUSED h->len_and_name[1+l] = 0; */ | ||
989 | if (l > 0) | 984 | if (l > 0) |
990 | f_read(h->len_and_name+1, l); | 985 | /* UNUSED */ f_read(h->len_and_name+1, l); |
986 | /* UNUSED h->len_and_name[1+l] = 0; */ | ||
991 | 987 | ||
992 | checksum = chksum_getresult(h->flags32); | 988 | checksum = chksum_getresult(h->flags32); |
993 | if (f_read32() != checksum) | 989 | if (f_read32() != checksum) |
@@ -998,12 +994,13 @@ static int read_header(header_t *h) | |||
998 | uint32_t extra_field_len; | 994 | uint32_t extra_field_len; |
999 | uint32_t extra_field_checksum; | 995 | uint32_t extra_field_checksum; |
1000 | uint32_t k; | 996 | uint32_t k; |
997 | char dummy; | ||
1001 | 998 | ||
1002 | /* note: the checksum also covers the length */ | 999 | /* note: the checksum also covers the length */ |
1003 | init_chksum(); | 1000 | init_chksum(); |
1004 | extra_field_len = f_read32(); | 1001 | extra_field_len = f_read32(); |
1005 | for (k = 0; k < extra_field_len; k++) | 1002 | for (k = 0; k < extra_field_len; k++) |
1006 | f_read8(); | 1003 | f_read(&dummy, 1); |
1007 | checksum = chksum_getresult(h->flags32); | 1004 | checksum = chksum_getresult(h->flags32); |
1008 | extra_field_checksum = f_read32(); | 1005 | extra_field_checksum = f_read32(); |
1009 | if (extra_field_checksum != checksum) | 1006 | if (extra_field_checksum != checksum) |