diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-05-02 20:06:51 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-05-02 20:06:51 (EDT) |
commit | 1e0e318b510dcd886b303f23f12652b60f1eb5b9 (patch) | |
tree | d068dfe4ba2ff42ec8a12298be4526ccf3d48928 /src | |
parent | f15f087cb77d44d8594836b353e5a77b1faeba28 (diff) |
gzip: Fix flushing
deflate() apparently must be called with avail_in=0 and Z_FINISH after
processing all input, not with Z_FINISH on the last non-empty input
buffer.
Diffstat (limited to 'src')
-rw-r--r-- | src/gzip.c | 17 | ||||
-rw-r--r-- | src/gzip.h | 3 | ||||
-rw-r--r-- | src/ustar.c | 8 |
3 files changed, 20 insertions, 8 deletions
@@ -174,8 +174,8 @@ opkg_opk_gzip_read(struct opkg_opk_gzip *gzip, void *record) } } -int -opkg_opk_gzip_write(struct opkg_opk_gzip *gzip, void *record, size_t size, +static int +_opkg_opk_gzip_write(struct opkg_opk_gzip *gzip, void *record, size_t size, int last) { /* Sanity check */ @@ -223,6 +223,16 @@ opkg_opk_gzip_write(struct opkg_opk_gzip *gzip, void *record, size_t size, } int +opkg_opk_gzip_write(struct opkg_opk_gzip *gzip, void *record, size_t size) +{ + if (_opkg_opk_gzip_write(gzip, record, size, 0) == OPKG_OPK_OK) { + return OPKG_OPK_OK; + } else { + return OPKG_OPK_ERROR; + } +} + +int opkg_opk_gzip_free(struct opkg_opk_gzip *gzip) { int ret; @@ -233,6 +243,9 @@ opkg_opk_gzip_free(struct opkg_opk_gzip *gzip) ret = OPKG_OPK_ERROR; } } else { + if (_opkg_opk_gzip_write(gzip, NULL, 0, 1) != OPKG_OPK_END) { + ret = OPKG_OPK_ERROR; + } if (deflateEnd(&gzip->stream) != Z_OK) { ret = OPKG_OPK_ERROR; } @@ -66,8 +66,7 @@ int opkg_opk_gzip_read(struct opkg_opk_gzip *gzip, void *record); int -opkg_opk_gzip_write(struct opkg_opk_gzip *gzip, void *record, size_t size, - int last); +opkg_opk_gzip_write(struct opkg_opk_gzip *gzip, void *record, size_t size); /* * Frees a decompression structure. diff --git a/src/ustar.c b/src/ustar.c index 88ae7b6..13e7621 100644 --- a/src/ustar.c +++ b/src/ustar.c @@ -334,7 +334,7 @@ opkg_opk_ustar_write_header(struct opkg_opk_ustar *ustar, sprintf(ustar->header.chksum, "%o", chksum); if (opkg_opk_gzip_write(ustar->gzip, &ustar->header, - OPKG_OPK_USTAR_RECORD_SIZE, 0) != OPKG_OPK_OK) { + OPKG_OPK_USTAR_RECORD_SIZE) != OPKG_OPK_OK) { return OPKG_OPK_ERROR; } @@ -365,7 +365,7 @@ opkg_opk_ustar_write_data(struct opkg_opk_ustar *ustar, size_t size) /* Write to gzip stream. */ if (opkg_opk_gzip_write(ustar->gzip, ustar->record, - OPKG_OPK_USTAR_RECORD_SIZE, 0) != OPKG_OPK_OK) { + OPKG_OPK_USTAR_RECORD_SIZE) != OPKG_OPK_OK) { return OPKG_OPK_ERROR; } @@ -378,9 +378,9 @@ opkg_opk_ustar_write_trailer(struct opkg_opk_ustar *ustar) { memset(ustar->record, 0, OPKG_OPK_USTAR_RECORD_SIZE); if (opkg_opk_gzip_write(ustar->gzip, ustar->record, - OPKG_OPK_USTAR_RECORD_SIZE, 0) != OPKG_OPK_OK || + OPKG_OPK_USTAR_RECORD_SIZE) != OPKG_OPK_OK || opkg_opk_gzip_write(ustar->gzip, ustar->record, - OPKG_OPK_USTAR_RECORD_SIZE, 1) != OPKG_OPK_END) + OPKG_OPK_USTAR_RECORD_SIZE) != OPKG_OPK_OK) { return OPKG_OPK_ERROR; } |