diff options
author | Patrick 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) |
commit | 53c6f9fb43624e4d48ef3a624dfe9511ef631c0e (patch) | |
tree | c7345bea4ab840db01ba345f4818a2439f6e5faa | |
parent | 5d36673e124b7edf3612988b4f8ed322f03baa65 (diff) |
gzip: Make more robust
-rw-r--r-- | src/gzip.c | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -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; + } } } |