diff --git a/runzip.c b/runzip.c index 55b1b6c..296b217 100644 --- a/runzip.c +++ b/runzip.c @@ -65,23 +65,30 @@ 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); - buf = malloc(len); - if (unlikely(!buf)) - fatal("Failed to malloc literal buffer of size %lld\n", len); + while (len > 0) { + i64 stream_read; - 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); + buf = (uchar *)malloc(len); + if (unlikely(!buf)) + fatal("Failed to malloc literal buffer of size %lld\n", len); - *cksum = CrcUpdate(*cksum, buf, 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); - free(buf); - return len; + *cksum = CrcUpdate(*cksum, buf, stream_read); + + free(buf); + len -= stream_read; + ret += stream_read; + } + return ret; } static i64 unzip_match(void *ss, i64 len, int fd_out, int fd_hist, uint32 *cksum, int chunk_bytes) @@ -106,7 +113,7 @@ static i64 unzip_match(void *ss, i64 len, int fd_out, int fd_hist, uint32 *cksum uchar *buf; n = MIN(len, offset); - buf = malloc(n); + buf = (uchar *)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 1cd18ac..43d261e 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))) - return -1; + fatal("Failed to fill_buffer from read_stream\n"); if (sinfo->s[stream].bufp == sinfo->s[stream].buflen) break; }