diff options
-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; + } } } |