Try limiting stream_read in unzip_literal and just returning how much was read.

This commit is contained in:
Con Kolivas 2011-02-10 16:57:22 +11:00
parent 9a3bfe33d1
commit 3879807865
2 changed files with 10 additions and 6 deletions

View file

@ -65,6 +65,7 @@ static i64 read_header(void *ss, uchar *head)
static i64 unzip_literal(void *ss, i64 len, int fd_out, uint32 *cksum)
{
i64 stream_read;
uchar *buf;
if (unlikely(len < 0))
@ -74,14 +75,17 @@ static i64 unzip_literal(void *ss, i64 len, int fd_out, uint32 *cksum)
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(stream_read == -1 ))
fatal("Failed to read_stream in unzip_literal\n");
*cksum = CrcUpdate(*cksum, 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, stream_read);
free(buf);
return len;
return stream_read;
}
static i64 unzip_match(void *ss, i64 len, int fd_out, int fd_hist, uint32 *cksum, int chunk_bytes)

View file

@ -1259,7 +1259,7 @@ i64 read_stream(void *ss, int stream, uchar *p, i64 len)
while (len) {
i64 n;
n = MIN(sinfo->s[stream].buflen-sinfo->s[stream].bufp, len);
n = MIN(sinfo->s[stream].buflen - sinfo->s[stream].bufp, len);
if (n > 0) {
memcpy(p, sinfo->s[stream].buf + sinfo->s[stream].bufp, n);