unexpand: fix stack overflow with large tabsizes

Resolves: RHEL-152110
This commit is contained in:
Lukáš Zaoral 2026-06-05 15:08:21 +02:00
parent e3c34cc523
commit b159cb2ef7
No known key found for this signature in database
GPG Key ID: 39157506DD67752D

View File

@ -33,8 +33,8 @@ Subject: [PATCH] coreutils-i18n.patch
tests/pr/pr-tests.pl | 49 +++
tests/sort/sort-merge.pl | 42 ++
tests/sort/sort.pl | 40 +-
tests/unexpand/mb.sh | 173 ++++++++
30 files changed, 3600 insertions(+), 196 deletions(-)
tests/unexpand/mb.sh | 179 ++++++++
30 files changed, 3606 insertions(+), 196 deletions(-)
create mode 100644 lib/mbchar.c
create mode 100644 lib/mbchar.h
create mode 100644 lib/mbfile.c
@ -4082,7 +4082,7 @@ index 09634197..dea94575 100644
break;
diff --git a/src/unexpand.c b/src/unexpand.c
index aca67dd7..f79c8088 100644
index aca67dd7..dacded6d 100644
--- a/src/unexpand.c
+++ b/src/unexpand.c
@@ -39,6 +39,9 @@
@ -4131,7 +4131,7 @@ index aca67dd7..f79c8088 100644
tab stop, then MAX_COLUMN_WIDTH - 1 blanks, then a non-blank; so
allocate MAX_COLUMN_WIDTH bytes to store the blanks. */
- pending_blank = xmalloc (max_column_width);
+ pending_blank = xmalloc (max_column_width * sizeof (mbf_char_t));
+ pending_blank = xinmalloc (max_column_width, sizeof (mbf_char_t));
+
+ if (found_bom == true)
+ {
@ -5000,10 +5000,10 @@ index d49f65f6..ebba9255 100755
my $verbose = $ENV{VERBOSE};
diff --git a/tests/unexpand/mb.sh b/tests/unexpand/mb.sh
new file mode 100644
index 00000000..f64542eb
index 00000000..89cac17b
--- /dev/null
+++ b/tests/unexpand/mb.sh
@@ -0,0 +1,173 @@
@@ -0,0 +1,179 @@
+#!/bin/sh
+
+# Copyright (C) 2012-2015 Free Software Foundation, Inc.
@ -5023,6 +5023,7 @@ index 00000000..f64542eb
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ unexpand
+getlimits_
+
+export LC_ALL=en_US.UTF-8
+
@ -5176,6 +5177,11 @@ index 00000000..f64542eb
+LC_ALL=C unexpand -a in in > out || fail=1
+compare exp out > /dev/null 2>&1 || fail=1
+
+for mb_mul in 4 6; do
+ printf ' \n' | unexpand -t $(expr $SIZE_MAX / $mb_mul + 1) 2>err; ret=$?
+ test "$ret" = 1 || test "$ret" = 0 || { cat err; fail=1; }
+done
+
+Exit $fail
--
2.54.0