From 609c119cf609e0764cb54be1403d2a334669e8ee Mon Sep 17 00:00:00 2001 From: arai Date: Tue, 4 Sep 2007 10:58:15 +0000 Subject: [PATCH] possible to extract 4G over files git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lha/lha/trunk@872 6a8cc165-1e22-0410-a132-eb4e3f353aba --- ChangeLog | 5 +++ src/append.c | 6 ++-- src/extract.c | 6 ++-- src/header.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/indicator.c | 6 ++-- src/lha.h | 14 ++++----- src/lhadd.c | 8 ++--- src/lhext.c | 14 ++++----- src/lhlist.c | 6 ++-- src/prototypes.h | 20 ++++++------ src/slide.c | 2 +- src/util.c | 12 ++++---- 12 files changed, 144 insertions(+), 47 deletions(-) mode change 100755 => 100644 ChangeLog diff --git a/ChangeLog b/ChangeLog old mode 100755 new mode 100644 index a849ce5..c67ee47 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-09-03 Koji Arai + + * src/append.c, src/extract.c, src/header.c, src/indicator.c, src/lha.h, src/lhadd.c, src/lhext.c, src/lhlist.c, src/prototypes.h, src/slide.c, src/util.c: + Possible to extract 4G over files, use UNLHA32.DLL specific extended header. + 2007-05-23 Koji Arai * tests/lha-test.in: added an optional numeric command-line diff --git a/src/append.c b/src/append.c index ee39ff3..ad6d4db 100644 --- a/src/append.c +++ b/src/append.c @@ -13,9 +13,9 @@ encode_lzhuf(infp, outfp, size, original_size_var, packed_size_var, name, hdr_method) FILE *infp; FILE *outfp; - size_t size; - size_t *original_size_var; - size_t *packed_size_var; + off_t size; + off_t *original_size_var; + off_t *packed_size_var; char *name; char *hdr_method; { diff --git a/src/extract.c b/src/extract.c index 674cd5e..814df7f 100644 --- a/src/extract.c +++ b/src/extract.c @@ -12,11 +12,11 @@ int decode_lzhuf(infp, outfp, original_size, packed_size, name, method, read_sizep) FILE *infp; FILE *outfp; - size_t original_size; - size_t packed_size; + off_t original_size; + off_t packed_size; char *name; int method; - size_t *read_sizep; + off_t *read_sizep; { unsigned int crc; struct interfacing interface; diff --git a/src/header.c b/src/header.c index e4c2d56..be35c66 100644 --- a/src/header.c +++ b/src/header.c @@ -161,6 +161,50 @@ put_longword(v) put_byte(v >> 24); } +#ifdef HAVE_UINT64_T +static uint64_t +get_longlongword() +{ + uint64_t b0, b1, b2, b3, b4, b5, b6, b7; + uint64_t l; + +#if DUMP_HEADER + if (verbose_listing && verbose > 1) + printf("%02d %2d: ", get_ptr - start_ptr, 4); +#endif + b0 = GET_BYTE(); + b1 = GET_BYTE(); + b2 = GET_BYTE(); + b3 = GET_BYTE(); + b4 = GET_BYTE(); + b5 = GET_BYTE(); + b6 = GET_BYTE(); + b7 = GET_BYTE(); + + l = (b7 << 24) + (b6 << 16) + (b5 << 8) + b4; + l <<= 32; + l |= (b3 << 24) + (b2 << 16) + (b1 << 8) + b0; +#if DUMP_HEADER + if (verbose_listing && verbose > 1) + printf("%lld(%#016llx)\n", l, l); +#endif + return l; +} + +static void +put_longlongword(uint64_t v) +{ + put_byte(v); + put_byte(v >> 8); + put_byte(v >> 16); + put_byte(v >> 24); + put_byte(v >> 32); + put_byte(v >> 40); + put_byte(v >> 48); + put_byte(v >> 56); +} +#endif + static int get_bytes(buf, len, size) char *buf; @@ -499,6 +543,10 @@ get_extended_header(fp, hdr, header_size, hcrc) name_length = strlen(hdr->name); while (header_size) { +#if DUMP_HEADER + if (verbose_listing && verbose > 1) + printf("---\n"); +#endif setup_get(data); if (sizeof(data) < header_size) { error("header size (%ld) too large.", header_size); @@ -513,6 +561,9 @@ get_extended_header(fp, hdr, header_size, hcrc) ext_type = get_byte(); switch (ext_type) { case 0: +#if DUMP_HEADER + if (verbose_listing && verbose > 1) printf(" < header crc >\n"); +#endif /* header crc (CRC-16) */ hdr->header_crc = get_word(); /* clear buffer for CRC calculation. */ @@ -520,21 +571,33 @@ get_extended_header(fp, hdr, header_size, hcrc) skip_bytes(header_size - n - 2); break; case 1: +#if DUMP_HEADER + if (verbose_listing && verbose > 1) printf(" < filename >\n"); +#endif /* filename */ name_length = get_bytes(hdr->name, header_size-n, sizeof(hdr->name)-1); hdr->name[name_length] = 0; break; case 2: +#if DUMP_HEADER + if (verbose_listing && verbose > 1) printf(" < directory >\n"); +#endif /* directory */ dir_length = get_bytes(dirname, header_size-n, sizeof(dirname)-1); dirname[dir_length] = 0; break; case 0x40: +#if DUMP_HEADER + if (verbose_listing && verbose > 1) printf(" < MS-DOS attribute >\n"); +#endif /* MS-DOS attribute */ hdr->attribute = get_word(); break; case 0x41: +#if DUMP_HEADER + if (verbose_listing && verbose > 1) printf(" < Windows time stamp (FILETIME) >\n"); +#endif /* Windows time stamp (FILETIME structure) */ /* it is time in 100 nano seconds since 1601-01-01 00:00:00 */ @@ -549,26 +612,55 @@ get_extended_header(fp, hdr, header_size, hcrc) skip_bytes(8); /* last access time is ignored */ break; + case 0x42: +#if DUMP_HEADER + if (verbose_listing && verbose > 1) printf(" < Windows file size header>\n"); +#endif +#ifdef HAVE_UINT64_T + /* Windows file size header (UNLHA32 extension) */ + hdr->packed_size = get_longlongword(); + hdr->original_size = get_longlongword(); +#else + skip_bytes(8); + skip_bytes(8); +#endif + + break; case 0x50: +#if DUMP_HEADER + if (verbose_listing && verbose > 1) printf(" < UNIX permission >\n"); +#endif /* UNIX permission */ hdr->unix_mode = get_word(); break; case 0x51: +#if DUMP_HEADER + if (verbose_listing && verbose > 1) printf(" < UNIX gid and uid >\n"); +#endif /* UNIX gid and uid */ hdr->unix_gid = get_word(); hdr->unix_uid = get_word(); break; case 0x52: +#if DUMP_HEADER + if (verbose_listing && verbose > 1) printf(" < UNIX group name >\n"); +#endif /* UNIX group name */ i = get_bytes(hdr->group, header_size-n, sizeof(hdr->group)-1); hdr->group[i] = '\0'; break; case 0x53: +#if DUMP_HEADER + if (verbose_listing && verbose > 1) printf(" < UNIX user name >\n"); +#endif /* UNIX user name */ i = get_bytes(hdr->user, header_size-n, sizeof(hdr->user)-1); hdr->user[i] = '\0'; break; case 0x54: +#if DUMP_HEADER + if (verbose_listing && verbose > 1) printf(" < UNIX last modifed time (time_t) >\n"); +#endif /* UNIX last modified time */ hdr->unix_last_modified_stamp = (time_t) get_longword(); break; diff --git a/src/indicator.c b/src/indicator.c index 5318f96..11da86f 100644 --- a/src/indicator.c +++ b/src/indicator.c @@ -11,10 +11,10 @@ #define MAX_INDICATOR_COUNT 58 -static size_t reading_size; +static off_t reading_size; #ifdef NEED_INCREMENTAL_INDICATOR -static size_t indicator_count; +static off_t indicator_count; static long indicator_threshold; #endif @@ -40,7 +40,7 @@ carriage_return() void start_indicator(name, size, msg, def_indicator_threshold) char *name; - size_t size; + off_t size; char *msg; long def_indicator_threshold; { diff --git a/src/lha.h b/src/lha.h index c990e29..e637001 100644 --- a/src/lha.h +++ b/src/lha.h @@ -251,8 +251,8 @@ typedef struct LzHeader { size_t header_size; int size_field_length; char method[METHOD_TYPE_STORAGE]; - size_t packed_size; - size_t original_size; + off_t packed_size; + off_t original_size; unsigned char attribute; unsigned char header_level; char name[FILENAME_LENGTH]; @@ -275,9 +275,9 @@ typedef struct LzHeader { struct interfacing { FILE *infile; FILE *outfile; - size_t original; - size_t packed; - size_t read_size; + off_t original; + off_t packed; + off_t read_size; int dicbit; int method; }; @@ -352,10 +352,10 @@ EXTERN int convertcase; /* 2000.10.6 */ /* slide.c */ EXTERN int unpackable; -EXTERN size_t origsize, compsize; +EXTERN off_t origsize, compsize; EXTERN unsigned short dicbit; EXTERN unsigned short maxmatch; -EXTERN size_t decode_count; +EXTERN off_t decode_count; EXTERN unsigned long loc; /* short -> long .. Changed N.Watazaki */ EXTERN unsigned char *text; diff --git a/src/lhadd.c b/src/lhadd.c index 5b12a5a..e37d821 100644 --- a/src/lhadd.c +++ b/src/lhadd.c @@ -20,7 +20,7 @@ add_one(fp, nafp, hdr) LzHeader *hdr; { off_t header_pos, next_pos, org_pos, data_pos; - size_t v_original_size, v_packed_size; + off_t v_original_size, v_packed_size; reading_filename = hdr->name; writing_filename = temporary_name; @@ -311,7 +311,7 @@ report_archive_name_if_different() /* ------------------------------------------------------------------------ */ void temporary_to_new_archive_file(new_archive_size) - size_t new_archive_size; + off_t new_archive_size; { FILE *oafp, *nafp; @@ -434,7 +434,7 @@ cmd_add() int i; long old_header; boolean old_archive_exist; - size_t new_archive_size; + off_t new_archive_size; /* exit if no operation */ if (!update_if_newer && cmd_filec == 0) { @@ -579,7 +579,7 @@ void cmd_delete() { FILE *oafp, *nafp; - size_t new_archive_size; + off_t new_archive_size; /* open old archive if exist */ if ((oafp = open_old_archive()) == NULL) diff --git a/src/lhext.c b/src/lhext.c index 96fcde1..dc6c3c3 100644 --- a/src/lhext.c +++ b/src/lhext.c @@ -215,7 +215,7 @@ adjust_info(name, hdr) } /* ------------------------------------------------------------------------ */ -static size_t +static off_t extract_one(afp, hdr) FILE *afp; /* archive file */ LzHeader *hdr; @@ -230,7 +230,7 @@ extract_one(afp, hdr) int method; boolean save_quiet, save_verbose, up_flag; char *q = hdr->name, c; - size_t read_size = 0; + off_t read_size = 0; if (ignore_directory && strrchr(hdr->name, '/')) { q = (char *) strrchr(hdr->name, '/') + 1; @@ -517,7 +517,7 @@ cmd_extract() LzHeader hdr; off_t pos; FILE *afp; - size_t read_size; + off_t read_size; /* open archive file */ if ((afp = open_old_archive()) == NULL) @@ -537,7 +537,7 @@ cmd_extract() if (pos != -1 && afp != stdin) fseeko(afp, pos + hdr.packed_size - read_size, SEEK_SET); else { - size_t i = hdr.packed_size - read_size; + off_t i = hdr.packed_size - read_size; while (i--) fgetc(afp); } } @@ -545,7 +545,7 @@ cmd_extract() if (afp != stdin) fseeko(afp, hdr.packed_size, SEEK_CUR); else { - size_t i = hdr.packed_size; + off_t i = hdr.packed_size; while (i--) fgetc(afp); } } @@ -638,13 +638,13 @@ static void adjust_dirinfo() static boolean decode_macbinary(ofp, size, outPath) FILE *ofp; - size_t size; + off_t size; const char *outPath; { af_file_t *afp = NULL; FILE *ifp = NULL; unsigned char *datap; - size_t dlen; + off_t dlen; if ((afp = af_open(temporary_name)) != NULL) { /* fetch datafork */ diff --git a/src/lhlist.c b/src/lhlist.c index e9b403b..a9ce07b 100644 --- a/src/lhlist.c +++ b/src/lhlist.c @@ -275,7 +275,7 @@ list_one(hdr) static void list_tailer(list_files, packed_size_total, original_size_total) int list_files; - unsigned long packed_size_total, original_size_total; + off_t packed_size_total, original_size_total; { struct stat stbuf; @@ -307,8 +307,8 @@ cmd_list() LzHeader hdr; int i; - unsigned long packed_size_total; - unsigned long original_size_total; + off_t packed_size_total; + off_t original_size_total; int list_files; /* initialize total count */ diff --git a/src/prototypes.h b/src/prototypes.h index e70b93b..42f4ab4 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -6,7 +6,7 @@ #endif /* append.c */ -int encode_lzhuf P_((FILE *infp, FILE *outfp, size_t size, size_t *original_size_var, size_t *packed_size_var, char *name, char *hdr_method)); +int encode_lzhuf P_((FILE *infp, FILE *outfp, off_t size, off_t *original_size_var, off_t *packed_size_var, char *name, char *hdr_method)); /* bitio.c */ void fillbuf P_((int n)); unsigned short getbits P_((int n)); @@ -30,7 +30,7 @@ unsigned short decode_p_dyn P_((void)); void output_dyn P_((unsigned int code, unsigned int pos)); void encode_end_dyn P_((void)); /* extract.c */ -int decode_lzhuf P_((FILE *infp, FILE *outfp, size_t original_size, size_t packed_size, char *name, int method, size_t *read_sizep)); +int decode_lzhuf P_((FILE *infp, FILE *outfp, off_t original_size, off_t packed_size, char *name, int method, off_t *read_sizep)); /* header.c */ int calc_sum P_((void *p, 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)); @@ -53,7 +53,7 @@ unsigned short decode_c_st1 P_((void)); unsigned short decode_p_st1 P_((void)); void decode_start_st1 P_((void)); /* indicator.c */ -void start_indicator P_((char *name, size_t size, char *msg, long def_indicator_threshold)); +void start_indicator P_((char *name, off_t size, char *msg, long def_indicator_threshold)); void put_indicator P_((long int count)); void finish_indicator2 P_((char *name, char *msg, int pcnt)); void finish_indicator P_((char *name, char *msg)); @@ -67,7 +67,7 @@ void decode_start_lz5 P_((void)); /* lhadd.c */ FILE *append_it P_((char *name, FILE *oafp, FILE *nafp)); FILE *build_temporary_file P_((void)); -void temporary_to_new_archive_file P_((size_t new_archive_size)); +void temporary_to_new_archive_file P_((off_t new_archive_size)); void cmd_add P_((void)); void cmd_delete P_((void)); /* lharc.c */ @@ -120,25 +120,25 @@ int encode_alloc P_((int method)); unsigned int encode P_((struct interfacing *interface)); unsigned int decode P_((struct interfacing *interface)); /* util.c */ -size_t copyfile P_((FILE *f1, FILE *f2, size_t size, int text_flg, unsigned int *crcp)); -int encode_stored_crc P_((FILE *ifp, FILE *ofp, size_t size, size_t *original_size_var, size_t *write_size_var)); +off_t copyfile P_((FILE *f1, FILE *f2, off_t size, int text_flg, unsigned int *crcp)); +int encode_stored_crc P_((FILE *ifp, FILE *ofp, off_t size, off_t *original_size_var, off_t *write_size_var)); boolean archive_is_msdos_sfx1 P_((char *name)); int xsnprintf P_((char *dest, size_t size, char *fmt, ...)); char *xstrchr P_((const char *s, int c)); char *xstrrchr P_((const char *s, int c)); -char *xmemchr P_((const char *s, int c, size_t n)); -char *xmemrchr P_((const char *s, int c, size_t n)); +char *xmemchr P_((const char *s, int c, off_t n)); +char *xmemrchr P_((const char *s, int c, off_t n)); int str_safe_copy P_((char *dst, const char *src, int dstsz)); /* util.c */ #if !HAVE_MEMMOVE -void *memmove P_((void *dst, const void *src, size_t cnt)); +void *memmove P_((void *dst, const void *src, off_t cnt)); #endif #if !HAVE_STRDUP char *strdup P_((const char *buf)); #endif #if !HAVE_MEMSET -char *memset P_((char *s, int c, size_t n)); +char *memset P_((char *s, int c, off_t n)); #endif #if !HAVE_STRCASECMP int strcasecmp P_((const char *p1, const char *p2)); diff --git a/src/slide.c b/src/slide.c index e8128d1..e73e317 100644 --- a/src/slide.c +++ b/src/slide.c @@ -295,7 +295,7 @@ encode(interface) struct interfacing *interface; { unsigned int token, pos, crc; - size_t count; + off_t count; struct matchdata match, last; #ifdef DEBUG diff --git a/src/util.c b/src/util.c index 3283e41..cb1047f 100644 --- a/src/util.c +++ b/src/util.c @@ -15,17 +15,17 @@ */ #include -size_t +off_t copyfile(f1, f2, size, text_flg, crcp) /* return: size of source file */ FILE *f1; FILE *f2; - size_t size; + off_t size; int text_flg; /* 0: binary, 1: read text, 2: write text */ unsigned int *crcp; { unsigned short xsize; char *buf; - size_t rsize = 0; + off_t rsize = 0; if (!text_mode) text_flg = 0; @@ -86,9 +86,9 @@ copyfile(f1, f2, size, text_flg, crcp) /* return: size of source file */ int encode_stored_crc(ifp, ofp, size, original_size_var, write_size_var) FILE *ifp, *ofp; - size_t size; - size_t *original_size_var; - size_t *write_size_var; + off_t size; + off_t *original_size_var; + off_t *write_size_var; { int save_quiet; unsigned int crc; -- 2.11.0