[packages/lrzip] Rel 4. Backport upstream fixes for heap overflows in recursive mode, empty TMPDIR handling and threa
arekm
arekm at pld-linux.org
Thu Oct 29 09:41:55 CET 2026
commit 35d882d88726741ca497d61b626ccb411dd3c6f4
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Thu Oct 29 07:29:27 2026 +0100
Rel 4. Backport upstream fixes for heap overflows in recursive mode,
empty TMPDIR handling and thread reduction (upstream #277, #278, #279).
lrzip-dirlist-overflow.patch | 57 +++++++++++++++++++++
lrzip-empty-tmpdir.patch | 26 ++++++++++
lrzip-lzma.patch | 48 ------------------
lrzip-thread-reduction.patch | 116 +++++++++++++++++++++++++++++++++++++++++++
lrzip.spec | 8 ++-
5 files changed, 206 insertions(+), 49 deletions(-)
---
diff --git a/lrzip.spec b/lrzip.spec
index 441a9c1..de32ab7 100644
--- a/lrzip.spec
+++ b/lrzip.spec
@@ -11,12 +11,15 @@ Summary: Long Range ZIP or Lzma RZIP
Summary(pl.UTF-8): Long Range ZIP lub Lzma RZIP
Name: lrzip
Version: 0.660
-Release: 3
+Release: 4
License: GPL v2
Group: Applications/Archiving
Source0: https://github.com/ckolivas/lrzip/archive/v%{version}/%{name}-%{version}.tar.gz
# Source0-md5: b4163b9bb9ed03d5cb858cdbe465f793
Patch0: %{name}-format.patch
+Patch1: %{name}-dirlist-overflow.patch
+Patch2: %{name}-empty-tmpdir.patch
+Patch3: %{name}-thread-reduction.patch
URL: https://github.com/ckolivas/lrzip
BuildRequires: autoconf >= 2.71
BuildRequires: automake >= 1.6
@@ -53,6 +56,9 @@ Dekompresja jest zawsze dużo szybsza niż bzip2.
%prep
%setup -q
%patch -P0 -p1
+%patch -P1 -p1
+%patch -P2 -p1
+%patch -P3 -p1
%build
%{__libtoolize}
diff --git a/lrzip-dirlist-overflow.patch b/lrzip-dirlist-overflow.patch
new file mode 100644
index 0000000..ee2774c
--- /dev/null
+++ b/lrzip-dirlist-overflow.patch
@@ -0,0 +1,57 @@
+Recursive -r directory list: int size overflow and unchecked realloc
+corrupt the heap past 524287 files; sprintf overflows fname on long paths.
+https://github.com/ckolivas/lrzip/issues/278
+Backport of https://github.com/ckolivas/lrzip/commit/c5abbbd6c1
+--- lrzip-0.660.orig/main.c 2026-10-29 02:17:36.410000000 +0100
++++ lrzip-0.660/main.c 2026-10-29 02:17:36.410000000 +0100
+@@ -272,7 +272,7 @@
+ }
+
+ /* Recursively enter all directories, adding all regular files to the dirlist array */
+-static void recurse_dirlist(char *indir, char **dirlist, int *entries)
++static void recurse_dirlist(char *indir, char **dirlist, size_t *entries)
+ {
+ char fname[MAX_PATH_LEN];
+ struct stat istat;
+@@ -283,9 +283,14 @@
+ if (unlikely(!dirp))
+ failure("Unable to open directory %s\n", indir);
+ while ((dp = readdir(dirp)) != NULL) {
++ char *new_dirlist;
++ int len;
++
+ if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
+ continue;
+- sprintf(fname, "%s/%s", indir, dp->d_name);
++ len = snprintf(fname, sizeof(fname), "%s/%s", indir, dp->d_name);
++ if (unlikely(len < 0 || (size_t)len >= sizeof(fname)))
++ failure("Path is too long: %s/%s\n", indir, dp->d_name);
+ if (unlikely(stat(fname, &istat)))
+ failure("Unable to stat file %s\n", fname);
+ if (S_ISDIR(istat.st_mode)) {
+@@ -297,8 +302,14 @@
+ continue;
+ }
+ print_maxverbose("Added file %s\n", fname);
+- *dirlist = realloc(*dirlist, MAX_PATH_LEN * (*entries + 1));
+- strcpy(*dirlist + MAX_PATH_LEN * (*entries)++, fname);
++ if (unlikely(*entries >= SIZE_MAX / MAX_PATH_LEN))
++ failure("Directory list is too large\n");
++ new_dirlist = realloc(*dirlist, MAX_PATH_LEN * (*entries + 1));
++ if (unlikely(!new_dirlist))
++ failure("Unable to grow recursive directory list\n");
++ *dirlist = new_dirlist;
++ strcpy(*dirlist + MAX_PATH_LEN * *entries, fname);
++ ++*entries;
+ }
+ closedir(dirp);
+ }
+@@ -620,7 +631,7 @@
+ /* One extra iteration for the case of no parameters means we will default to stdin/out */
+ for (i = 0; i <= argc; i++) {
+ char *dirlist = NULL, *infile = NULL;
+- int direntries = 0, curentry = 0;
++ size_t direntries = 0, curentry = 0;
+
+ if (i < argc)
+ infile = argv[i];
diff --git a/lrzip-empty-tmpdir.patch b/lrzip-empty-tmpdir.patch
new file mode 100644
index 0000000..b1dd9e5
--- /dev/null
+++ b/lrzip-empty-tmpdir.patch
@@ -0,0 +1,26 @@
+An empty TMPDIR/TMP/TEMPDIR/TEMP makes initialise_control() read tmpdir[-1].
+https://github.com/ckolivas/lrzip/issues/277
+Backport of https://github.com/ckolivas/lrzip/commit/cb8d7b707d
+--- lrzip-0.660.orig/lrzip.c 2026-10-29 02:17:36.419999999 +0100
++++ lrzip-0.660/lrzip.c 2026-10-29 02:17:36.423333332 +0100
+@@ -1530,15 +1530,15 @@
+ if (unlikely(!get_rand(control, control->salt + 2, 6)))
+ return false;
+
+- /* Get Temp Dir. Try variations on canonical unix environment variable */
++ /* Get Temp Dir. Skip unset or empty environment variables. */
+ eptr = getenv("TMPDIR");
+- if (!eptr)
++ if (!eptr || !*eptr)
+ eptr = getenv("TMP");
+- if (!eptr)
++ if (!eptr || !*eptr)
+ eptr = getenv("TEMPDIR");
+- if (!eptr)
++ if (!eptr || !*eptr)
+ eptr = getenv("TEMP");
+- if (!eptr)
++ if (!eptr || !*eptr)
+ eptr = localeptr;
+ len = strlen(eptr);
+
diff --git a/lrzip-lzma.patch b/lrzip-lzma.patch
deleted file mode 100644
index 99d82b8..0000000
--- a/lrzip-lzma.patch
+++ /dev/null
@@ -1,48 +0,0 @@
---- lrzip-0.16/Makefile.in.orig 2006-10-31 14:09:01.000000000 +0100
-+++ lrzip-0.16/Makefile.in 2006-11-01 13:48:57.651380250 +0100
-@@ -23,24 +23,7 @@
- .SUFFIXES:
- .SUFFIXES: .c .o
-
--OBJS= rzip.o runzip.o main.o stream.o util.o crc32.o\
-- LZMADecoder.o \
-- LZMAEncoder.o \
-- LZInWindow.o \
-- LZOutWindow.o \
-- RangeCoderBit.o \
-- InBuffer.o \
-- OutBuffer.o \
-- FileStreams.o \
-- Alloc.o \
-- C_FileIO.o \
-- CommandLineParser.o \
-- CRC.o \
-- String.o \
-- StringConvert.o \
-- StringToInt.o \
-- Vector.o \
-- LZMALib.o \
-+OBJS= rzip.o runzip.o main.o stream.o util.o crc32.o
-
-
- # note that the -I. is needed to handle config.h when using VPATH
-@@ -115,7 +98,7 @@
- cd lzma && make && cd ../
-
- lrzip: $(OBJS)
-- $(CXX) $(CXXFLAGS) -o lrzip $(OBJS) $(LIBS)
-+ $(CXX) $(CXXFLAGS) -o lrzip $(OBJS) -llzma $(LIBS)
-
- lrzip.1: lrzip.yo
- yodl2man -o lrzip.1 lrzip.yo
---- lrzip-0.16/stream.c.orig 2006-10-31 14:17:12.000000000 +0100
-+++ lrzip-0.16/stream.c 2006-11-01 13:48:39.182226000 +0100
-@@ -20,7 +20,7 @@
-
- #include "rzip.h"
- #include "bzlib.h"
--#include "lzma/lzmalib.h"
-+#include <lzmalib.h>
-
- #define CTYPE_NONE 3
- #define CTYPE_BZIP2 4
diff --git a/lrzip-thread-reduction.patch b/lrzip-thread-reduction.patch
new file mode 100644
index 0000000..555fef1
--- /dev/null
+++ b/lrzip-thread-reduction.patch
@@ -0,0 +1,116 @@
+clear_buffer() keeps a static slot index across files, so after
+open_stream_out() lowers control->threads it indexes past cthreads[] and
+threads[] (heap overflow). https://github.com/ckolivas/lrzip/issues/279
+Backport of https://github.com/ckolivas/lrzip/commit/d34dbc6b48 (plus the
+wait_streamout_threads() helper 0.660 lacks).
+--- lrzip-0.660.orig/stream.c 2026-10-29 02:17:36.443333333 +0100
++++ lrzip-0.660/stream.c 2026-10-29 02:17:36.446666666 +0100
+@@ -84,6 +84,7 @@
+ } stream_thread_struct;
+
+ static long output_thread;
++static int next_compress_thread;
+ static pthread_mutex_t output_lock = PTHREAD_MUTEX_INITIALIZER;
+ static pthread_cond_t output_cond = PTHREAD_COND_INITIALIZER;
+
+@@ -926,6 +927,11 @@
+ cksem_init(control, &cthreads[i].cksem);
+ cksem_post(control, &cthreads[i].cksem);
+ }
++ /* A new file gets a new pool and a fresh output order. */
++ next_compress_thread = 0;
++ lock_mutex(control, &output_lock);
++ output_thread = 0;
++ unlock_mutex(control, &output_lock);
+ return true;
+ }
+
+@@ -947,6 +953,24 @@
+ return true;
+ }
+
++/* Wait for every queued compthread to finish, leaving the pool usable */
++static bool wait_streamout_threads(rzip_control *control)
++{
++ int i, close_thread;
++
++ lock_mutex(control, &output_lock);
++ close_thread = output_thread;
++ unlock_mutex(control, &output_lock);
++
++ for (i = 0; i < control->threads; i++) {
++ cksem_wait(control, &cthreads[close_thread].cksem);
++ cksem_post(control, &cthreads[close_thread].cksem);
++ if (++close_thread == control->threads)
++ close_thread = 0;
++ }
++ return true;
++}
++
+ /* open a set of output streams, compressing with the given
+ compression level and algorithm */
+ void *open_stream_out(rzip_control *control, int f, unsigned int n, i64 chunk_limit, char cbytes)
+@@ -954,6 +978,7 @@
+ struct stream_info *sinfo;
+ unsigned int i, testbufs;
+ bool threadlimit = false, memlimit = false;
++ int active_threads = control->threads;
+ i64 testsize, limit;
+ uchar *testmalloc;
+
+@@ -984,22 +1009,30 @@
+ else
+ testbufs = 2;
+
+- testsize = (limit * testbufs) + (control->overhead * control->threads);
++ testsize = (limit * testbufs) + (control->overhead * active_threads);
+ if (testsize > control->usable_ram)
+- limit = (control->usable_ram - (control->overhead * control->threads)) / testbufs;
++ limit = (control->usable_ram - (control->overhead * active_threads)) / testbufs;
+
+ /* If we don't have enough ram for the number of threads, decrease the
+ * number of threads till we do, or only have one thread. */
+ while (limit < STREAM_BUFSIZE && limit < chunk_limit) {
+- if (control->threads > 1) {
+- --control->threads;
++ if (active_threads > 1) {
++ --active_threads;
+ threadlimit = true;
+ } else
+ break;
+- limit = (control->usable_ram - (control->overhead * control->threads)) / testbufs;
++ limit = (control->usable_ram - (control->overhead * active_threads)) / testbufs;
+ limit = MIN(limit, chunk_limit);
+ }
+ if (threadlimit) {
++ /* Previous chunks may still be writing with the old pool size.
++ * Drain them before changing either cursor or their wrap limit. */
++ wait_streamout_threads(control);
++ control->threads = active_threads;
++ next_compress_thread = 0;
++ lock_mutex(control, &output_lock);
++ output_thread = 0;
++ unlock_mutex(control, &output_lock);
+ print_output("Minimising number of threads to %d to limit memory usage\n",
+ control->threads);
+ }
+@@ -1507,7 +1540,7 @@
+ {
+ pthread_t *threads = control->pthreads;
+ stream_thread_struct *s;
+- static int i = 0;
++ int i = next_compress_thread;
+
+ /* Make sure this thread doesn't already exist */
+ cksem_wait(control, &cthreads[i].cksem);
+@@ -1540,8 +1573,9 @@
+ sinfo->s[streamno].buflen = 0;
+ }
+
+- if (++i == control->threads)
++ if (++i >= control->threads)
+ i = 0;
++ next_compress_thread = i;
+ }
+
+ /* flush out any data in a stream buffer */
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/lrzip.git/commitdiff/35d882d88726741ca497d61b626ccb411dd3c6f4
More information about the pld-cvs-commit
mailing list