[packages/poldek] Rel 0.2. Fix poldek -e crashing on packages with many files

arekm arekm at pld-linux.org
Sun Nov 1 18:31:05 CET 2026


commit 80c4de28e038eefbf475ea3621a99f35482d7815
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Sun Nov 1 18:30:22 2026 +0100

    Rel 0.2. Fix poldek -e crashing on packages with many files

 poldek-uninstall-many-files.patch | 116 ++++++++++++++++++++++++++++++++++++++
 poldek.spec                       |   4 +-
 2 files changed, 119 insertions(+), 1 deletion(-)
---
diff --git a/poldek.spec b/poldek.spec
index d2b41a3..6f2f797 100644
--- a/poldek.spec
+++ b/poldek.spec
@@ -17,7 +17,7 @@
 
 %define		gitref	a82dd5f8db02518dee2b88891f681cdcd2edaed0
 %define		snap	20261031
-%define		rel	0.1
+%define		rel	0.2
 # poldek's autogen.sh and CI build against trurlib and tndb master
 %define		trurlib_gitref	c8e868cf50b8a67930bb6ff6945aa01b89734e15
 %define		tndb_gitref	27a90b4cca45533e84afc57e0a9654dfbf0120d1
@@ -52,6 +52,7 @@ Source102:	%{name}-debuginfo-snap.conf
 Patch0:		%{name}-config.patch
 Patch1:		pm-hooks.patch
 Patch2:		%{name}-ext-down-enable.patch
+Patch3:		%{name}-uninstall-many-files.patch
 URL:		http://poldek.pld-linux.org/
 BuildRequires:	autoconf >= 2.63
 BuildRequires:	automake >= 1:1.11
@@ -233,6 +234,7 @@ cd ..
 %patch -P0 -p1
 %patch -P1 -p1
 %patch -P2 -p1
+%patch -P3 -p1
 
 # what upstream autogen.sh does besides autotools
 %{__make} -f Makefile.extra POTFILES_in
diff --git a/poldek-uninstall-many-files.patch b/poldek-uninstall-many-files.patch
new file mode 100644
index 0000000..102c29d
--- /dev/null
+++ b/poldek-uninstall-many-files.patch
@@ -0,0 +1,116 @@
+From 9957007ba1ac5ed6466099701eb32bbc0be9614a Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Arkadiusz=20Mi=C5=9Bkiewicz?= <arekm at maven.pl>
+Date: Sun, 1 Nov 2026 14:51:28 +0100
+Subject: [PATCH] fix: removing a package with many files overflowed the stack
+
+Removing a package looks up what requires each of its files, and
+--greedy does the same for each file of a requirement it may take along.
+Both loops made the capreq of each path with capreq_new_name_a(), with
+alloca(), which is freed only when the function returns, so the stack
+grew with every path. Removing aws-sdk-cpp-devel, 83,819 files with 5 MB
+of paths, overflowed the 8 MB stack and poldek died with SIGSEGV.
+
+Both loops now take the capreq from the heap and free it after the
+query, as install3/obsoletes.c does in the same kind of loop, and the
+macro says what its alloca() means for a loop.
+---
+ capreq.h        |  2 ++
+ tests/sh/08-rpm | 34 ++++++++++++++++++++++++++++++++++
+ uninstall.c     | 12 +++++++-----
+ 3 files changed, 43 insertions(+), 5 deletions(-)
+
+diff --git a/capreq.h b/capreq.h
+index 6ae408d4..3a2be9d9 100644
+--- a/capreq.h
++++ b/capreq.h
+@@ -113,6 +113,8 @@ EXPORT struct capreq *capreq_new(tn_alloc *na, const char *name, int32_t epoch,
+                                  const char *version, const char *release,
+                                  int32_t relflags, int32_t flags);
+ #ifndef SWIG
++/* alloca(): the capreq lives until the caller returns, too long for a loop
++   over a list of any length */
+ #define capreq_new_name_a(nam, crptr)                              \
+     {                                                              \
+         struct capreq *__cr;                                       \
+diff --git a/tests/sh/08-rpm b/tests/sh/08-rpm
+index d17609d7..0a5eef35 100755
+--- a/tests/sh/08-rpm
++++ b/tests/sh/08-rpm
+@@ -768,6 +768,40 @@ testUpgradeMultipleInstalledWithDeps() {
+     try_install a "a-1.1.1k-1" "a-1.1.1j-1"
+ }
+ 
++# poldek -e on a 512 kB stack: room enough for poldek, but not for a stack
++# that grows with each file
++uninstall_on_small_stack() {
++    local expected="$1" out rc
++    shift
++
++    out=$(ulimit -s 512; $RAW_POLDEK --root $DESTINATION_REPO -ev --test \
++              --parsable-tr-summary "$@" 2>&1)
++    rc=$?
++    assertEquals "-e $*: exit code $rc: $(echo "$out" | tail -1)" "0" "$rc"
++    out=$(echo "$out" | grep -E '^%[RD]' | sort | tr '\n' ' ')
++    assertEquals "-e $*: removed" "$expected" "$out"
++}
++
++# removal looks up what requires each file of a package it takes, and so does
++# --greedy for each file of a requirement it may take along; neither may need
++# stack for each file. The long names stay under the 255 bytes a file list
++# keeps: longer ones are skipped, and the test would pass without the fix.
++testUninstallManyFiles() {
++    skip_if_rpm_testing_off && return
++    local dir=/opt/zzmany/$(printf '%0200d' 0) files="" last i
++
++    for i in $(seq 1200); do
++        last=$dir/$(printf '%0230d' $i)
++        files="$files -f $last"
++    done
++    build_installed a 1-1 $files
++    build_installed b 1-1 -r $last
++
++    uninstall_on_small_stack "%D b-1-1.noarch %R a-1-1.noarch " a
++    uninstall_on_small_stack "%D a-1-1.noarch %D sh-1-1.noarch %R b-1-1.noarch " \
++                             --greedy b
++}
++
+ # poldek's rpmlog() hides rpm's notices such as "<file>: digests OK"
+ testInstallRpmNoticesFiltered() {
+     skip_if_rpm_testing_off && return
+diff --git a/uninstall.c b/uninstall.c
+index 28626fa5..5a56a995 100644
+--- a/uninstall.c
++++ b/uninstall.c
+@@ -103,12 +103,12 @@ tn_array *get_orphanedby_pkg(struct uninstall_ctx *uctx, struct pkg *pkg)
+ 
+         pkgfl_it_init(&it, pkg->fl);
+         while ((path = pkgfl_it_get(&it, NULL))) {
+-            struct capreq *cap;
+-            capreq_new_name_a(path, cap);
++            struct capreq *cap = capreq_new(NULL, path, 0, NULL, NULL, 0, 0);
+             tracef(0, "%s of %s", pkg_id(pkg), path);
+ 
+             pkgdb_q_what_requires(uctx->db, orphans, cap,
+                                   uctx->unpkgs, ldflags, 0);
++            capreq_free(cap);
+         }
+     }
+ 
+@@ -149,9 +149,11 @@ static int pkg_leave_orphans(struct uninstall_ctx *uctx, struct pkg *pkg)
+ 
+         pkgfl_it_init(&it, pkg->fl);
+         while ((path = pkgfl_it_get(&it, NULL))) {
+-            struct capreq *cap;
+-            capreq_new_name_a(path, cap);
+-            if (pkgdb_q_is_required(uctx->db, cap, exclude))
++            struct capreq *cap = capreq_new(NULL, path, 0, NULL, NULL, 0, 0);
++            int required = pkgdb_q_is_required(uctx->db, cap, exclude);
++
++            capreq_free(cap);
++            if (required)
+                 goto l_yes;
+         }
+     }
+-- 
+2.56.0
+
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/poldek.git/commitdiff/80c4de28e038eefbf475ea3621a99f35482d7815



More information about the pld-cvs-commit mailing list