From 28edd18ccae761547972793898ba104e927d0f29 Mon Sep 17 00:00:00 2001 From: arai Date: Sun, 24 Nov 2002 18:16:15 +0000 Subject: [PATCH] * src/header.c: use size_t for header_size. (skip_msdos_sfx1_code): rename to `seek_lha_header'. * src/lha.h: use size_t for header_size. * src/lhadd.c (cmd_add): rename to `seek_lha_header'. (cmd_delete): ditto. * src/lhext.c (cmd_extract): ditto. * src/lhlist.c (cmd_list): ditto. * src/prototypes.h: updated. * tests/lha-test15: added tests to search any level headers. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lha/lha/trunk@591 6a8cc165-1e22-0410-a132-eb4e3f353aba --- src/header.c | 62 +++++++++++++++++++++++++++++++------------------------- src/lha.h | 2 +- src/lhadd.c | 4 ++-- src/lhext.c | 2 +- src/lhlist.c | 2 +- src/prototypes.h | 2 +- tests/lha-test15 | 47 ++++++++++++++++++++++++++++++++++++------ 7 files changed, 81 insertions(+), 40 deletions(-) diff --git a/src/header.c b/src/header.c index e67efe5..4ad9e68 100644 --- a/src/header.c +++ b/src/header.c @@ -555,11 +555,11 @@ wintime_to_unix_stamp() * size field is 4 bytes */ -static long +static ssize_t get_extended_header(fp, hdr, header_size, hcrc) FILE *fp; LzHeader *hdr; - long header_size; + size_t header_size; unsigned int *hcrc; { char data[LZHEADER_STORAGE]; @@ -567,7 +567,7 @@ get_extended_header(fp, hdr, header_size, hcrc) char dirname[FILENAME_LENGTH]; int dir_length = 0; int i; - long whole_size = header_size; + ssize_t whole_size = header_size; int ext_type; int n = 1 + hdr->size_field_length; /* `ext-type' + `next-header size' */ @@ -765,11 +765,11 @@ get_header_level0(fp, hdr, data) LzHeader *hdr; char *data; { - int header_size; + size_t header_size; + ssize_t extend_size; int checksum; int name_length; int i; - int extend_size; hdr->size_field_length = 2; /* in bytes */ hdr->header_size = header_size = get_byte(); @@ -881,7 +881,8 @@ get_header_level1(fp, hdr, data) LzHeader *hdr; char *data; { - int header_size, extend_size; + size_t header_size; + ssize_t extend_size; int checksum; int name_length; int i, dummy; @@ -974,7 +975,8 @@ get_header_level2(fp, hdr, data) LzHeader *hdr; char *data; { - int header_size, extend_size; + size_t header_size; + ssize_t extend_size; int padding; unsigned int hcrc; @@ -1054,7 +1056,8 @@ get_header_level3(fp, hdr, data) LzHeader *hdr; char *data; { - long header_size, extend_size; + size_t header_size; + ssize_t extend_size; int padding; unsigned int hcrc; @@ -1212,11 +1215,11 @@ get_header(fp, hdr) } /* skip SFX header */ -boolean -skip_msdos_sfx1_code(fp) - FILE *fp; +int +seek_lha_header(fp) + FILE *fp; { - unsigned char buffer[64 * 1024]; /* SFX header size */ + unsigned char buffer[64 * 1024]; /* max seek size */ unsigned char *p; int n; @@ -1229,25 +1232,28 @@ skip_msdos_sfx1_code(fp) /* size and checksum validate check */ - /* level 0 header */ - if (p[I_HEADER_LEVEL] == 0 + /* level 0 or 1 header */ + if ((p[I_HEADER_LEVEL] == 0 || p[I_HEADER_LEVEL] == 1) && p[I_HEADER_SIZE] > 20 && p[I_HEADER_CHECKSUM] == calc_sum(p+2, p[I_HEADER_SIZE])) { - fseek(fp, (p - buffer) - n, SEEK_CUR); - return TRUE; + if (fseek(fp, (p - buffer) - n, SEEK_CUR) == -1) + fatal_error("cannot seek header"); + return 0; } /* level 2 header */ if (p[I_HEADER_LEVEL] == 2 && p[I_HEADER_SIZE] >= 24 && p[I_ATTRIBUTE] == 0x20) { - fseek(fp, (p - buffer) - n, SEEK_CUR); - return TRUE; + if (fseek(fp, (p - buffer) - n, SEEK_CUR) == -1) + fatal_error("cannot seek header"); + return 0; } } - fseek(fp, -n, SEEK_CUR); - return FALSE; + if (fseek(fp, -n, SEEK_CUR) == -1) + fatal_error("cannot seek header"); + return -1; } /* ------------------------------------------------------------------------ */ @@ -1365,14 +1371,14 @@ write_unix_info(hdr) /* ------------------------------------------------------------------------ */ /* Write unix extended header or generic header. */ -static int +static size_t write_header_level0(data, hdr, pathname) LzHeader *hdr; char *data, *pathname; { int limit; int name_length; - int header_size; + size_t header_size; setup_put(data); memset(data, 0, LZHEADER_STORAGE); @@ -1423,16 +1429,16 @@ write_header_level0(data, hdr, pathname) return header_size + 2; } -static int +static size_t write_header_level1(data, hdr, pathname) LzHeader *hdr; char *data, *pathname; { int name_length, dir_length, limit; char *basename, *dirname; - int header_size; + size_t header_size; char *extend_header_top; - int extend_header_size; + size_t extend_header_size; basename = strrchr(pathname, LHA_PATHSEP); if (basename) { @@ -1515,14 +1521,14 @@ write_header_level1(data, hdr, pathname) return header_size + extend_header_size + 2; } -static int +static size_t write_header_level2(data, hdr, pathname) LzHeader *hdr; char *data, *pathname; { int name_length, dir_length; char *basename, *dirname; - int header_size; + size_t header_size; char *extend_header_top; char *headercrc_ptr; unsigned int hcrc; @@ -1612,7 +1618,7 @@ write_header(fp, hdr) FILE *fp; LzHeader *hdr; { - int header_size; + size_t header_size; char data[LZHEADER_STORAGE]; int archive_kanji_code = CODE_SJIS; diff --git a/src/lha.h b/src/lha.h index 9a6a5ac..e0a73b6 100644 --- a/src/lha.h +++ b/src/lha.h @@ -222,7 +222,7 @@ struct string_pool { }; typedef struct LzHeader { - long header_size; + size_t header_size; int size_field_length; char method[METHOD_TYPE_STORAGE]; long packed_size; diff --git a/src/lhadd.c b/src/lhadd.c index da94837..68a4b16 100644 --- a/src/lhadd.c +++ b/src/lhadd.c @@ -466,7 +466,7 @@ cmd_add() } if (oafp && archive_is_msdos_sfx1(archive_name)) { - skip_msdos_sfx1_code(oafp); + seek_lha_header(oafp); build_standard_archive_name(new_archive_name_buffer, archive_name); new_archive_name = new_archive_name_buffer; } @@ -570,7 +570,7 @@ cmd_delete() } if (archive_is_msdos_sfx1(archive_name)) { - skip_msdos_sfx1_code(oafp); + seek_lha_header(oafp); build_standard_archive_name(new_archive_name_buffer, archive_name); new_archive_name = new_archive_name_buffer; } diff --git a/src/lhext.c b/src/lhext.c index 6142c8b..285c284 100644 --- a/src/lhext.c +++ b/src/lhext.c @@ -430,7 +430,7 @@ cmd_extract() fatal_error("Cannot open archive file \"%s\"", archive_name); if (archive_is_msdos_sfx1(archive_name)) - skip_msdos_sfx1_code(afp); + seek_lha_header(afp); /* extract each files */ while (get_header(afp, &hdr)) { diff --git a/src/lhlist.c b/src/lhlist.c index dafc4ae..b1733ab 100644 --- a/src/lhlist.c +++ b/src/lhlist.c @@ -322,7 +322,7 @@ cmd_list() exit(1); } if (archive_is_msdos_sfx1(archive_name)) - skip_msdos_sfx1_code(afp); + seek_lha_header(afp); /* print header message */ if (!quiet) diff --git a/src/prototypes.h b/src/prototypes.h index f2c3754..e581446 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -39,7 +39,7 @@ int decode_lzhuf P_((FILE *infp, FILE *outfp, long original_size, long packed_si int calc_sum P_((register char *p, register int len)); void convert_filename P_((char *name, int len, int size, int from_code, int to_code, char *from_delim, char *to_delim, int case_to)); boolean get_header P_((FILE *fp, LzHeader *hdr)); -boolean skip_msdos_sfx1_code P_((FILE *fp)); +int seek_lha_header P_((FILE *fp)); void init_header P_((char *name, struct stat *v_stat, LzHeader *hdr)); void write_header P_((FILE *fp, LzHeader *hdr)); char *sjis_to_utf8 P_((char *dst, const char *src, size_t dstsize)); diff --git a/tests/lha-test15 b/tests/lha-test15 index b227cce..cb85486 100644 --- a/tests/lha-test15 +++ b/tests/lha-test15 @@ -4,17 +4,52 @@ message testing to self extracting archive if test -c /dev/zero; then # Usually, size of SFX code is less than 20K - dd if=/dev/zero of=test-tmp-1.exe bs=1024 count=20 2>/dev/null + dd if=/dev/zero of=test-tmp-hg.exe bs=1024 count=20 2>/dev/null else # dummy header - echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > test-tmp-1.exe + echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > test-tmp-hg.exe fi check $? $LINENO -$lha c - test-[abc] >> test-tmp-1.exe +cp test-tmp-hg.exe test-tmp-h0.exe && +cp test-tmp-hg.exe test-tmp-h1.exe && +cp test-tmp-hg.exe test-tmp-h2.exe check $? $LINENO -$lha v test-tmp-1.exe +# generic header +$lha cg - test-[abc] >> test-tmp-hg.exe check $? $LINENO -$lha xw=test-tmp-1 test-tmp-1.exe +$lha vv test-tmp-hg.exe check $? $LINENO -diff -r test-1 test-tmp-1 +$lha xw=test-tmp-hg test-tmp-hg.exe + check $? $LINENO +diff -r test-1 test-tmp-hg + check $? $LINENO + +# level 0 header +$lha c0 - test-[abc] >> test-tmp-h0.exe + check $? $LINENO +$lha vv test-tmp-h0.exe + check $? $LINENO +$lha xw=test-tmp-h0 test-tmp-h0.exe + check $? $LINENO +diff -r test-1 test-tmp-h0 + check $? $LINENO + +# level 1 header +$lha c1 - test-[abc] >> test-tmp-h1.exe + check $? $LINENO +$lha vv test-tmp-h1.exe + check $? $LINENO +$lha xw=test-tmp-h1 test-tmp-h1.exe + check $? $LINENO +diff -r test-1 test-tmp-h1 + check $? $LINENO + +# level 2 header +$lha c2 - test-[abc] >> test-tmp-h2.exe + check $? $LINENO +$lha vv test-tmp-h2.exe + check $? $LINENO +$lha xw=test-tmp-h2 test-tmp-h2.exe + check $? $LINENO +diff -r test-1 test-tmp-h2 check $? $LINENO -- 2.11.0