From 9a3bfe33d1753dc3e221b0b0f966466abf8acec9 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 10 Feb 2011 16:46:35 +1100 Subject: [PATCH] Revert "Make sure to read the full length asked of unzip_literal." This reverts commit 499ae18cef66086cf7819497cfdff85f9c798308. Wrong fix, revert it. --- runzip.c | 29 +++++++++++------------------ stream.c | 2 +- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/runzip.c b/runzip.c index 296b217..55b1b6c 100644 --- a/runzip.c +++ b/runzip.c @@ -65,30 +65,23 @@ static i64 read_header(void *ss, uchar *head) static i64 unzip_literal(void *ss, i64 len, int fd_out, uint32 *cksum) { - i64 ret = 0; uchar *buf; if (unlikely(len < 0)) - fatal("len %lld is negative in unzip_literal!\n", len); + fatal("len %lld is negative in unzip_literal!\n",len); - while (len > 0) { - i64 stream_read; + buf = malloc(len); + if (unlikely(!buf)) + fatal("Failed to malloc literal buffer of size %lld\n", len); - buf = (uchar *)malloc(len); - if (unlikely(!buf)) - fatal("Failed to malloc literal buffer of size %lld\n", len); + read_stream(ss, 1, buf, len); + if (unlikely(write_1g(fd_out, buf, (size_t)len) != (ssize_t)len)) + fatal("Failed to write literal buffer of size %lld\n", len); - stream_read = read_stream(ss, 1, buf, len); - if (unlikely(write_1g(fd_out, buf, (size_t)stream_read) != (ssize_t)stream_read)) - fatal("Failed to write literal buffer of size %lld\n", stream_read); + *cksum = CrcUpdate(*cksum, buf, len); - *cksum = CrcUpdate(*cksum, buf, stream_read); - - free(buf); - len -= stream_read; - ret += stream_read; - } - return ret; + free(buf); + return len; } static i64 unzip_match(void *ss, i64 len, int fd_out, int fd_hist, uint32 *cksum, int chunk_bytes) @@ -113,7 +106,7 @@ static i64 unzip_match(void *ss, i64 len, int fd_out, int fd_hist, uint32 *cksum uchar *buf; n = MIN(len, offset); - buf = (uchar *)malloc(n); + buf = malloc(n); if (unlikely(!buf)) fatal("Failed to malloc match buffer of size %lld\n", n); diff --git a/stream.c b/stream.c index 43d261e..1cd18ac 100644 --- a/stream.c +++ b/stream.c @@ -1271,7 +1271,7 @@ i64 read_stream(void *ss, int stream, uchar *p, i64 len) if (len && sinfo->s[stream].bufp == sinfo->s[stream].buflen) { if (unlikely(fill_buffer(sinfo, stream))) - fatal("Failed to fill_buffer from read_stream\n"); + return -1; if (sinfo->s[stream].bufp == sinfo->s[stream].buflen) break; }