summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/archive.c6
-rw-r--r--src/gunzip.c48
-rw-r--r--src/package.c4
3 files changed, 32 insertions, 26 deletions
diff --git a/src/archive.c b/src/archive.c
index 7c26502..af0055e 100644
--- a/src/archive.c
+++ b/src/archive.c
@@ -225,10 +225,10 @@ int apk_tar_parse(struct apk_istream *is, apk_archive_entry_parser parser,
}
/* Check that there was no partial record */
- if (r != 0)
- return -1;
+ if (r > 0)
+ r = -1;
- return 0;
+ return r;
err:
EVP_MD_CTX_cleanup(&teis.mdctx);
diff --git a/src/gunzip.c b/src/gunzip.c
index 3f9a253..8ccfbab 100644
--- a/src/gunzip.c
+++ b/src/gunzip.c
@@ -21,7 +21,7 @@ struct apk_gzip_istream {
struct apk_istream is;
struct apk_bstream *bs;
z_stream zs;
- int z_err;
+ int err;
apk_multipart_cb cb;
void *cbctx;
@@ -34,10 +34,11 @@ static size_t gzi_read(void *stream, void *ptr, size_t size)
container_of(stream, struct apk_gzip_istream, is);
int r;
- if (gis->z_err == Z_DATA_ERROR || gis->z_err == Z_ERRNO)
- return -1;
- if (gis->z_err == Z_STREAM_END)
- return 0;
+ if (gis->err != 0) {
+ if (gis->err > 0)
+ return 0;
+ return gis->err;
+ }
if (ptr == NULL)
return apk_istream_skip(&gis->is, size);
@@ -45,7 +46,7 @@ static size_t gzi_read(void *stream, void *ptr, size_t size)
gis->zs.avail_out = size;
gis->zs.next_out = ptr;
- while (gis->zs.avail_out != 0 && gis->z_err == Z_OK) {
+ while (gis->zs.avail_out != 0 && gis->err == 0) {
if (gis->zs.avail_in == 0) {
apk_blob_t blob;
@@ -59,48 +60,54 @@ static size_t gzi_read(void *stream, void *ptr, size_t size)
gis->zs.avail_in = blob.len;
gis->zs.next_in = (void *) gis->cbprev;
if (gis->zs.avail_in < 0) {
- gis->z_err = Z_DATA_ERROR;
- return size - gis->zs.avail_out;
+ gis->err = -1;
+ goto ret;
} else if (gis->zs.avail_in == 0) {
if (gis->cb != NULL) {
r = gis->cb(gis->cbctx, APK_MPART_END,
APK_BLOB_NULL);
if (r != 0) {
- gis->z_err = Z_STREAM_END;
if (r > 0)
r = -1;
- return r;
+ gis->err = r;
}
- }
- gis->z_err = Z_STREAM_END;
- return size - gis->zs.avail_out;
+ } else
+ gis->err = 1;
+ goto ret;
}
}
- gis->z_err = inflate(&gis->zs, Z_NO_FLUSH);
- if (gis->z_err == Z_STREAM_END) {
+ r = inflate(&gis->zs, Z_NO_FLUSH);
+ switch (r) {
+ case Z_STREAM_END:
/* Digest the inflated bytes */
if (gis->cb != NULL) {
r = gis->cb(gis->cbctx, APK_MPART_BOUNDARY,
APK_BLOB_PTR_LEN(gis->cbprev,
(void *)gis->zs.next_in - gis->cbprev));
if (r != 0) {
- gis->z_err = Z_DATA_ERROR;
if (r > 0)
r = -1;
- return r;
+ gis->err = r;
+ goto ret;
}
gis->cbprev = gis->zs.next_in;
}
inflateEnd(&gis->zs);
if (inflateInit2(&gis->zs, 15+32) != Z_OK)
return -1;
- gis->z_err = Z_OK;
+ break;
+ case Z_OK:
+ break;
+ default:
+ gis->err = -1;
+ break;
}
}
- if (gis->z_err != Z_OK && gis->z_err != Z_STREAM_END)
- return -1;
+ret:
+ if (size - gis->zs.avail_out == 0)
+ return gis->err;
return size - gis->zs.avail_out;
}
@@ -131,7 +138,6 @@ struct apk_istream *apk_bstream_gunzip_mpart(struct apk_bstream *bs,
.is.read = gzi_read,
.is.close = gzi_close,
.bs = bs,
- .z_err = 0,
.cb = cb,
.cbctx = ctx,
};
diff --git a/src/package.c b/src/package.c
index 78f7cb6..44b4232 100644
--- a/src/package.c
+++ b/src/package.c
@@ -447,7 +447,7 @@ int apk_sign_ctx_mpart_cb(void *ctx, int part, apk_blob_t data)
/* Package identity is checksum of control block */
sctx->identity.type = EVP_MD_CTX_size(&sctx->mdctx);
EVP_DigestFinal_ex(&sctx->mdctx, sctx->identity.data, NULL);
- return 1;
+ return -1000;
} else {
/* Reset digest for hashing data */
EVP_DigestFinal_ex(&sctx->mdctx, calculated, NULL);
@@ -702,7 +702,7 @@ struct apk_package *apk_pkg_read(struct apk_database *db, const char *file,
tar = apk_bstream_gunzip_mpart(bs, apk_sign_ctx_mpart_cb, sctx);
r = apk_tar_parse(tar, read_info_entry, &ctx);
tar->close(tar);
- if (r < 0)
+ if (r < 0 && r != -1000)
goto err;
if (ctx.pkg->name == NULL)
goto err;