commit - 3606d7fc8ecd88d9779619bbe6cb06f5309258cc
commit + 61d262a8cb97715b621fe46595c9b84e04d7f8ec
blob - 9e010e01438667bfc74ee881619187962c92dc5a
blob + e53d687aa859dea281f6a14ea293c7f2bdcd1ae9
--- lib/pack.c
+++ lib/pack.c
}
/* Delta streams should always fit in memory. */
- err = got_inflate_to_mem(&delta_buf, &delta_len, delta_file,
- delta->size);
+ err = got_inflate_to_mem(&delta_buf, &delta_len, delta_file);
if (err)
return err;
blob - 16623c1a51d435399ec53d6b1ee7e22e0803d766
blob + 0d9155f03530fc133e275ca4b33e4415aa2d0413
--- lib/zb.c
+++ lib/zb.c
ret = inflate(z, Z_SYNC_FLUSH);
} while (ret == Z_OK && z->avail_out > 0);
- if (ret != Z_OK) {
+ if (ret == Z_OK) {
+ zb->flags |= GOT_ZSTREAM_F_HAVE_MORE;
+ } else {
if (ret != Z_STREAM_END)
return got_error(GOT_ERR_DECOMPRESSION);
- zb->flags |= GOT_ZSTREAM_F_HAVE_MORE;
+ zb->flags &= ~GOT_ZSTREAM_F_HAVE_MORE;
}
*outlenp = z->total_out - last_total_out;
}
const struct got_error *
-got_inflate_to_mem(uint8_t **outbuf, size_t *outlen, FILE *f, size_t insize)
+got_inflate_to_mem(uint8_t **outbuf, size_t *outlen, FILE *f)
{
const struct got_error *err;
- size_t inbytes, consumed, avail;
+ size_t consumed, avail;
struct got_zstream_buf zb;
void *newbuf;
*outbuf = NULL;
*outlen = 0;
- inbytes = 0;
- while (1) {
+ do {
err = got_inflate_read(&zb, f, &consumed, &avail);
if (err)
return err;
- inbytes += consumed;
- if (avail == 0) {
- if (insize && inbytes < insize)
- err = got_error(GOT_ERR_BAD_DELTA);
- break;
+ if (avail > 0) {
+ newbuf = reallocarray(*outbuf, 1, *outlen + avail);
+ if (newbuf == NULL) {
+ free(*outbuf);
+ *outbuf = NULL;
+ *outlen = 0;
+ err = got_error(GOT_ERR_NO_MEM);
+ goto done;
+ }
+ memcpy(newbuf + *outlen, zb.outbuf, avail);
+ *outbuf = newbuf;
+ *outlen += avail;
}
- newbuf = reallocarray(*outbuf, 1, *outlen + avail);
- if (newbuf == NULL) {
- free(*outbuf);
- *outbuf = NULL;
- *outlen = 0;
- err = got_error(GOT_ERR_NO_MEM);
- goto done;
- }
- memcpy(newbuf + *outlen, zb.outbuf, avail);
- *outbuf = newbuf;
- *outlen += avail;
- };
+ } while (zb.flags & GOT_ZSTREAM_F_HAVE_MORE);
done:
got_inflate_end(&zb);
blob - f71dcda43ea4ef3e830b9e148737e73c3e15fa89
blob + e5294017e24d1cec6c532ded4529d174d7b65155
--- lib/zb.h
+++ lib/zb.h
const struct got_error *got_inflate_read(struct got_zstream_buf *, FILE *,
size_t *, size_t *);
void got_inflate_end(struct got_zstream_buf *);
-const struct got_error *got_inflate_to_mem(uint8_t **, size_t *, FILE *,
- size_t);
+const struct got_error *got_inflate_to_mem(uint8_t **, size_t *, FILE *);
const struct got_error *got_inflate_to_file(size_t *, FILE *, FILE *);