From b27e1df879d1374d6395182e5437c0790f95179d Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 23 Mar 2011 07:59:04 +1100 Subject: [PATCH] Revert "Modify the file format to not include rzip chunk size except for STDOUT chunked files thus decreasing the file format size further." This reverts commit 131d4c92c27afb100bfa97f151f65b899aabb991. Breaks STDIN/OUT so revert this change and cope with the slightly extra file size on non-chunked files. --- doc/magic.header.txt | 2 +- liblrzip.h | 1 - lrzip.c | 28 ++++++++-------------------- lrzip_private.h | 1 - main.c | 1 - stream.c | 6 +++--- 6 files changed, 12 insertions(+), 27 deletions(-) diff --git a/doc/magic.header.txt b/doc/magic.header.txt index d0ef0b1..1eea48b 100644 --- a/doc/magic.header.txt +++ b/doc/magic.header.txt @@ -28,7 +28,7 @@ Encrypted salt (bytes 6->14 in magic if encrypted): Rzip Chunk Data: 0 Data offsets byte width (meaning length is < (2 * 8)^RCD0) 1 Flag that there is no chunk beyond this -(RCD0 bytes) Chunk decompressed size (only stored in stdout chunked file) +(RCD0 bytes) Chunk decompressed size (not stored in encrypted file) XX Stream 0 header data XX Stream 1 header data diff --git a/liblrzip.h b/liblrzip.h index e62cd0f..d817af0 100644 --- a/liblrzip.h +++ b/liblrzip.h @@ -49,7 +49,6 @@ #define TMP_OUTBUF (control->flags & FLAG_TMP_OUTBUF) #define TMP_INBUF (control->flags & FLAG_TMP_INBUF) #define ENCRYPT (control->flags & FLAG_ENCRYPT) -#define CHUNKED (control->flags & FLAG_CHUNKED) #define print_output(format, args...) do {\ fprintf(control->msgout, format, ##args); \ diff --git a/lrzip.c b/lrzip.c index d90ec65..f56ed8a 100644 --- a/lrzip.c +++ b/lrzip.c @@ -178,10 +178,6 @@ static void get_magic(rzip_control *control, char *magic) print_output("Asked to decrypt a non-encrypted archive. Bypassing decryption.\n"); control->flags &= ~FLAG_ENCRYPT; } - /* If the file was generated from STDOUT and !ENCRYPT, an extra field - * describing the chunk length exists */ - if (!ENCRYPT && !expected_size) - control->flags |= FLAG_CHUNKED; } void read_magic(rzip_control *control, int fd_in, i64 *expected_size) @@ -794,11 +790,9 @@ void get_fileinfo(rzip_control *control) if (control->major_version == 0 && control->minor_version > 5) { if (unlikely(read(fd_in, &control->eof, 1) != 1)) fatal("Failed to read eof in get_fileinfo\n"); - if (CHUNKED) { - if (unlikely(read(fd_in, &chunk_size, chunk_byte) != chunk_byte)) - fatal("Failed to read chunk_size in get_fileinfo\n"); - chunk_size = le64toh(chunk_size); - } + if (unlikely(read(fd_in, &chunk_size, chunk_byte) != chunk_byte)) + fatal("Failed to read chunk_size in get_fileinfo\n"); + chunk_size = le64toh(chunk_size); } } @@ -812,7 +806,7 @@ void get_fileinfo(rzip_control *control) ofs = 25; header_length = 25; } else { - ofs = 26 + (CHUNKED ? chunk_byte: 0); + ofs = 26 + chunk_byte; header_length = 1 + (chunk_byte * 3); } next_chunk: @@ -886,13 +880,10 @@ next_chunk: if (control->major_version == 0 && control->minor_version > 5) { if (unlikely(read(fd_in, &control->eof, 1) != 1)) fatal("Failed to read eof in get_fileinfo\n"); - ofs++; - if (CHUNKED) { - if (unlikely(read(fd_in, &chunk_size, chunk_byte) != chunk_byte)) - fatal("Failed to read chunk_size in get_fileinfo\n"); - chunk_size = le64toh(chunk_size); - ofs += chunk_byte; - } + if (unlikely(read(fd_in, &chunk_size, chunk_byte) != chunk_byte)) + fatal("Failed to read chunk_size in get_fileinfo\n"); + chunk_size = le64toh(chunk_size); + ofs += 1 + chunk_byte; header_length = 1 + (chunk_byte * 3); } } @@ -971,9 +962,6 @@ void compress_file(rzip_control *control) if (ENCRYPT) get_hash(control, 1); - else if (STDOUT) - control->flags |= FLAG_CHUNKED; - memset(header, 0, sizeof(header)); if (!STDIN) { diff --git a/lrzip_private.h b/lrzip_private.h index cf67926..b6e94e6 100644 --- a/lrzip_private.h +++ b/lrzip_private.h @@ -153,7 +153,6 @@ typedef struct md5_ctx md5_ctx; #define FLAG_TMP_OUTBUF (1 << 21) #define FLAG_TMP_INBUF (1 << 22) #define FLAG_ENCRYPT (1 << 23) -#define FLAG_CHUNKED (1 << 24) #define NO_MD5 (!(HASH_CHECK) && !(HAS_MD5)) diff --git a/main.c b/main.c index 92d90a9..b4d6b2b 100644 --- a/main.c +++ b/main.c @@ -88,7 +88,6 @@ #define TMP_OUTBUF (control.flags & FLAG_TMP_OUTBUF) #define TMP_INBUF (control.flags & FLAG_TMP_INBUF) #define ENCRYPT (control.flags & FLAG_ENCRYPT) -#define CHUNKED (control.flags & FLAG_CHUNKED) #define print_output(format, args...) do {\ fprintf(control.msgout, format, ##args); \ diff --git a/stream.c b/stream.c index 852c4c7..0873114 100644 --- a/stream.c +++ b/stream.c @@ -1119,7 +1119,7 @@ void *open_stream_in(rzip_control *control, int f, int n, char chunk_bytes) goto failed; } /* Read in the expected chunk size */ - if (CHUNKED) { + if (!ENCRYPT) { if (unlikely(read_val(control, f, &sinfo->size, sinfo->chunk_bytes))) { print_err("Failed to read in chunk size in open_stream_in\n"); goto failed; @@ -1340,9 +1340,9 @@ retry: write_u8(control, ctis->fd, ctis->chunk_bytes); /* Write whether this is the last chunk, followed by the size - * of this chunk if working with STDOUT and !ENCRYPT */ + * of this chunk */ write_u8(control, ctis->fd, control->eof); - if (CHUNKED) + if (!ENCRYPT) write_val(control, ctis->fd, ctis->size, ctis->chunk_bytes); /* First chunk of this stream, write headers */