[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] fold: fix output truncation with 0xFF bytes in input
|
From: |
Pádraig Brady |
|
Subject: |
[PATCH 1/2] fold: fix output truncation with 0xFF bytes in input |
|
Date: |
Wed, 4 Mar 2026 18:04:01 +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 | 3 +++
gl/lib/mbbuf.h | 2 +-
tests/fold/fold-characters.sh | 9 +++++----
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/NEWS b/NEWS
index 7eb70b6d1..340115ecc 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 9054fc92e..ea4b7e708 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 b44276eaa..5af9856f6 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
--
2.53.0
- [PATCH 1/2] fold: fix output truncation with 0xFF bytes in input,
Pádraig Brady <=