Skip to content
Snippets Groups Projects
Commit efbdd5e1 authored by Timo Teräs's avatar Timo Teräs
Browse files

main/apk-tools: cherry-pick fix for index generation

parent 35220b8c
No related branches found
No related tags found
No related merge requests found
From 6b6cbf5d546b36d73d47f2663d5a572eac0cbfe8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
Date: Mon, 1 Apr 2024 14:14:11 +0300
Subject: [PATCH] io: fix gunzip mpart handling regression
The _DATA callback needs to be deferred until extracted data is
handled for the state machine to work correctly for identity data
generation.
fixes regresion in "apk index"
fixes 9855169e "io: simplify mpart and error handling"
(cherry picked from commit b7a7ea728e242a04f32f8e56ddc3d8d85960ee28)
---
src/io_gunzip.c | 47 +++++++++++++++++++++++++++--------------------
1 file changed, 27 insertions(+), 20 deletions(-)
diff --git a/src/io_gunzip.c b/src/io_gunzip.c
index 2724963..6c56fcb 100644
--- a/src/io_gunzip.c
+++ b/src/io_gunzip.c
@@ -23,7 +23,7 @@ struct apk_gzip_istream {
apk_multipart_cb cb;
void *cbctx;
void *cbprev;
- uint8_t boundary;
+ apk_blob_t cbarg;
};
static void gzi_get_meta(struct apk_istream *is, struct apk_file_meta *meta)
@@ -36,7 +36,14 @@ static int gzi_boundary_change(struct apk_gzip_istream *gis)
{
int r;
- gis->boundary = 0;
+ if (gis->cb && !APK_BLOB_IS_NULL(gis->cbarg)) {
+ r = gis->cb(gis->cbctx, APK_MPART_DATA, gis->cbarg);
+ if (r) {
+ gis->is.err = r;
+ return r;
+ }
+ }
+ gis->cbarg = APK_BLOB_NULL;
if (!gis->is.err && gis->zis->err && gis->zs.avail_in == 0) gis->is.err = gis->zis->err;
if (!gis->cb) return 0;
r = gis->cb(gis->cbctx, gis->is.err ? APK_MPART_END : APK_MPART_BOUNDARY, APK_BLOB_NULL);
@@ -48,18 +55,6 @@ static int gzi_boundary_change(struct apk_gzip_istream *gis)
static int gzi_read_more(struct apk_gzip_istream *gis)
{
apk_blob_t blob;
- int r;
-
- if (gis->cb != NULL && gis->cbprev != NULL && gis->cbprev != gis->zs.next_in) {
- r = gis->cb(gis->cbctx, APK_MPART_DATA,
- APK_BLOB_PTR_LEN(gis->cbprev, (void *)gis->zs.next_in - gis->cbprev));
- if (r < 0) {
- gis->is.err = r;
- return gis->is.err;
- }
- gis->cbprev = gis->zs.next_in;
- }
- if (gis->zs.avail_in) return 0;
blob = apk_istream_get_all(gis->zis);
if (blob.len <= 0) {
@@ -84,11 +79,20 @@ static ssize_t gzi_read(struct apk_istream *is, void *ptr, size_t size)
gis->zs.next_out = ptr;
while (gis->zs.avail_out != 0 && gis->is.err >= 0) {
- if (gis->boundary) {
+ if (!APK_BLOB_IS_NULL(gis->cbarg)) {
r = gzi_boundary_change(gis);
if (r) return r;
}
if (gis->zs.avail_in == 0 && gis->is.err == 0) {
+ if (gis->cb != NULL && gis->cbprev != NULL && gis->cbprev != gis->zs.next_in) {
+ r = gis->cb(gis->cbctx, APK_MPART_DATA,
+ APK_BLOB_PTR_LEN(gis->cbprev, (void *)gis->zs.next_in - gis->cbprev));
+ if (r < 0) {
+ gis->is.err = r;
+ return r;
+ }
+ gis->cbprev = gis->zs.next_in;
+ }
r = gzi_read_more(gis);
if (r) return r;
}
@@ -96,12 +100,15 @@ static ssize_t gzi_read(struct apk_istream *is, void *ptr, size_t size)
r = inflate(&gis->zs, Z_NO_FLUSH);
switch (r) {
case Z_STREAM_END:
- gis->boundary = 1;
-
+ if (gis->cb != NULL) {
+ gis->cbarg = APK_BLOB_PTR_LEN(gis->cbprev, (void *) gis->zs.next_in - gis->cbprev);
+ gis->cbprev = gis->zs.next_in;
+ }
/* Digest the inflated bytes */
- r = gzi_read_more(gis);
- if (r) return r;
-
+ if (gis->zs.avail_in == 0) {
+ r = gzi_read_more(gis);
+ if (r) return r;
+ }
/* If we hit end of the bitstream (not end
* of just this gzip), we need to do the
* callback here, as we won't be called again.
--
2.44.0
# Maintainer: Natanael Copa <ncopa@alpinelinux.org> # Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=apk-tools pkgname=apk-tools
pkgver=2.14.2 pkgver=2.14.2
pkgrel=0 pkgrel=1
pkgdesc="Alpine Package Keeper - package manager for alpine" pkgdesc="Alpine Package Keeper - package manager for alpine"
arch="all" arch="all"
url="https://gitlab.alpinelinux.org/alpine/apk-tools" url="https://gitlab.alpinelinux.org/alpine/apk-tools"
...@@ -28,6 +28,7 @@ if [ "$CBUILD" = "$CHOST" ]; then ...@@ -28,6 +28,7 @@ if [ "$CBUILD" = "$CHOST" ]; then
depends="$depends ca-certificates-bundle" depends="$depends ca-certificates-bundle"
fi fi
source="https://gitlab.alpinelinux.org/alpine/apk-tools/-/archive/v$pkgver/apk-tools-v$pkgver.tar.gz source="https://gitlab.alpinelinux.org/alpine/apk-tools/-/archive/v$pkgver/apk-tools-v$pkgver.tar.gz
0001-io-fix-gunzip-mpart-handling-regression.patch
_apk _apk
" "
builddir="$srcdir/$pkgname-v$pkgver" builddir="$srcdir/$pkgname-v$pkgver"
...@@ -92,5 +93,6 @@ luaapk() { ...@@ -92,5 +93,6 @@ luaapk() {
sha512sums=" sha512sums="
13d0e0ff873dbb9d5ec61eb7f88ae02823e9bf6022cdac3b242f1edad4cc90e488dc01de5d9fd3adc594dc7f25286428f0dda5704ad150820273105669ce82bf apk-tools-v2.14.2.tar.gz 13d0e0ff873dbb9d5ec61eb7f88ae02823e9bf6022cdac3b242f1edad4cc90e488dc01de5d9fd3adc594dc7f25286428f0dda5704ad150820273105669ce82bf apk-tools-v2.14.2.tar.gz
7079ac4b7f7178cc43c5eb1c9d68a79a0cb5e6dd217c77c4c050bc779bae510325e63a49ab0f2c030facaf5fcaefc64b6f948bfd939c2c20afd29c9f54b3a98d 0001-io-fix-gunzip-mpart-handling-regression.patch
7870676720f5007eee9482786e02246f8e3474afb90e76c9c83aebe914747a8e007b5d2eed6441933f4922024b3f0664db270f21981ad6c2db877a110b0cd79e _apk 7870676720f5007eee9482786e02246f8e3474afb90e76c9c83aebe914747a8e007b5d2eed6441933f4922024b3f0664db270f21981ad6c2db877a110b0cd79e _apk
" "
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment