Make sure to read the full length asked of unzip_literal.

This commit is contained in:
Con Kolivas 2011-02-10 15:30:31 +11:00
parent 0a32b5f72d
commit 499ae18cef
2 changed files with 19 additions and 12 deletions

View file

@ -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) static i64 unzip_literal(void *ss, i64 len, int fd_out, uint32 *cksum)
{ {
i64 ret = 0;
uchar *buf; uchar *buf;
if (unlikely(len < 0)) 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); while (len > 0) {
i64 stream_read;
buf = (uchar *)malloc(len);
if (unlikely(!buf)) if (unlikely(!buf))
fatal("Failed to malloc literal buffer of size %lld\n", len); fatal("Failed to malloc literal buffer of size %lld\n", len);
read_stream(ss, 1, buf, len); stream_read = read_stream(ss, 1, buf, len);
if (unlikely(write_1g(fd_out, buf, (size_t)len) != (ssize_t)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", len); 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); free(buf);
return len; 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) 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; uchar *buf;
n = MIN(len, offset); n = MIN(len, offset);
buf = malloc(n); buf = (uchar *)malloc(n);
if (unlikely(!buf)) if (unlikely(!buf))
fatal("Failed to malloc match buffer of size %lld\n", n); fatal("Failed to malloc match buffer of size %lld\n", n);

View file

@ -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 (len && sinfo->s[stream].bufp == sinfo->s[stream].buflen) {
if (unlikely(fill_buffer(sinfo, stream))) 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) if (sinfo->s[stream].bufp == sinfo->s[stream].buflen)
break; break;
} }