summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-04-17 10:27:09 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-04-17 10:27:09 (EDT)
commit53c6f9fb43624e4d48ef3a624dfe9511ef631c0e (patch)
treec7345bea4ab840db01ba345f4818a2439f6e5faa
parent5d36673e124b7edf3612988b4f8ed322f03baa65 (diff)
gzip: Make more robust
-rw-r--r--src/gzip.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/gzip.c b/src/gzip.c
index de733f9..302ba72 100644
--- a/src/gzip.c
+++ b/src/gzip.c
@@ -60,36 +60,49 @@ opkg_opk_gzip_init(opkg_opk_gzip_read_func *read, void *user_data)
int
opkg_opk_gzip_read(struct opkg_opk_gzip *gzip, void *record)
{
+ int end;
+
gzip->stream.next_out = record;
gzip->stream.avail_out = OPKG_OPK_USTAR_RECORD_SIZE;
for (;;) {
+ end = 0;
if (gzip->stream.avail_in == 0) {
/* Input buffer is empty and needs refilled. */
switch (gzip->read(gzip->user_data,
&gzip->stream.next_in,
&gzip->stream.avail_in)) {
case OPKG_OPK_OK:
+ break;
case OPKG_OPK_END:
+ end = 1;
break;
case OPKG_OPK_ERROR:
default:
return OPKG_OPK_ERROR;
}
}
- if (gzip->stream.avail_out == 0) {
- /* Output buffer is filled and ready for use. */
- return OPKG_OPK_OK;
- }
switch (inflate(&gzip->stream, Z_SYNC_FLUSH)) {
case Z_OK:
+ break;
case Z_BUF_ERROR:
+ if (end == 1) {
+ return OPKG_OPK_ERROR;
+ }
break;
case Z_STREAM_END:
+ if (gzip->stream.avail_out != 0) {
+ /* Premature end */
+ return OPKG_OPK_ERROR;
+ }
return OPKG_OPK_END;
default:
return OPKG_OPK_ERROR;
}
+ if (gzip->stream.avail_out == 0) {
+ /* Output buffer is filled and ready for use. */
+ return OPKG_OPK_OK;
+ }
}
}