From: Pádraig Brady
Date: Wed, 4 Mar 2026 16:56:48 +0000 (+0000) Subject: fold: fix output truncation with 0xFF bytes in input X-Git-Tag: v9.11~195 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a85e9182b1d173c26205dada54133cd9e9174fc1;p=thirdparty%2Fcoreutils.git fold: fix output truncation with 0xFF bytes in input 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 --- diff --git a/NEWS b/NEWS index 7eb70b6d15..340115eccf 100644 --- 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] diff --git a/gl/lib/mbbuf.h b/gl/lib/mbbuf.h index 9054fc92e0..ea4b7e7087 100644 --- a/gl/lib/mbbuf.h +++ b/gl/lib/mbbuf.h @@ -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; } diff --git a/tests/fold/fold-characters.sh b/tests/fold/fold-characters.sh index b44276eaa7..5af9856f65 100755 --- a/tests/fold/fold-characters.sh +++ b/tests/fold/fold-characters.sh @@ -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