]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
fold: fix output truncation with 0xFF bytes in input
authorPádraig Brady <P@draigBrady.com>
Wed, 4 Mar 2026 16:56:48 +0000 (16:56 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 4 Mar 2026 17:45:57 +0000 (17:45 +0000)
On signed char platforms, 0xFF was converted to -1
which matches MBBUF_EOF, causing fold to stop processing.

* NEWS: Mention the bug fix.
* gl/lib/mbbuf.h: Avoid sign extension on signed char platforms.
* tests/fold/fold-characters.sh: Adjust test case.
Reported at https://src.fedoraproject.org/rpms/coreutils/pull-request/20

NEWS
gl/lib/mbbuf.h
tests/fold/fold-characters.sh

diff --git a/NEWS b/NEWS
index 7eb70b6d157acbbff956fd07ef9c860fee9b6b49..340115eccfc9bfd3894566fd3ecd53221fa59b2e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 ** Bug fixes
 
+  'fold' will no longer truncate output when encountering 0xFF bytes.
+  [bug introduced in coreutils-9.8]
+
   'kill --help' now has links to valid anchors in the html manual.
   [bug introduced in coreutils-9.10]
 
index 9054fc92e0ea2f934152eab2abe918c7928193f5..ea4b7e7087bc3ce581c6d43581393e4969b797dd 100644 (file)
@@ -96,7 +96,7 @@ mbbuf_get_char (mbbuf_t *mbbuf)
   else
     {
       /* Assume the program will emit the byte, but keep the error flag.  */
-      g.ch = mbbuf->buffer[mbbuf->offset++];
+      g.ch = (unsigned char) mbbuf->buffer[mbbuf->offset++];
     }
   return g;
 }
index b44276eaa7d0f900399e92b8df8684001ccfb601..5af9856f65851f57760b56a5477002edd806031a 100755 (executable)
@@ -87,11 +87,12 @@ compare exp3 out3 || fail=1
 bad_unicode_with_nul ()
 {
   # invalid UTF8|unpaired surrogate|NUL|C1 control|noncharacter
-  env printf '\xC3|\xED\xBA\xAD|\u0000|\u0089|\xED\xA6\xBF\xED\xBF\xBF\n'
+  env printf '\xFF|\xED\xBA\xAD|\u0000|\u0089|\xED\xA6\xBF\xED\xBF\xBF\n'
 }
-bad_unicode_with_nul > /dev/null || framework_failure_
-test $({ bad_unicode_with_nul | fold; \
-         bad_unicode_with_nul; } | uniq | wc -l) = 1 || fail=1
+bad_unicode_with_nul > exp4 || framework_failure_
+bad_unicode_with_nul | fold > out4 || fail=1
+compare exp4 out4 || fail=1
+
 # Check bad character at EOF
 test $(env printf '\xC3' | fold | wc -c) = 1 || fail=1