Test for issue https://sourceware.org/PR35092 fixed with the previous gnulib commit ????????
* tests/numfmt/mb-delim-len.sh: Add a new test. * tests/local.mk: Reference the new test. * NEWS: Mention the bug fix. Discovered by Anthropic's OSS Scanner, as bug ANT-2026-2X6T1GCH. --- NEWS | 5 ++++ tests/local.mk | 1 + tests/numfmt/mb-delim-len.sh | 47 ++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100755 tests/numfmt/mb-delim-len.sh diff --git a/NEWS b/NEWS index 94e912b57..b11786299 100644 --- a/NEWS +++ b/NEWS @@ -257,6 +257,11 @@ GNU coreutils NEWS -*- outline -*- silently converted to 99000 rather than being diagnosed as invalid. [bug introduced in coreutils-9.9] + 'numfmt -d' and 'numfmt -s' no longer has buffer overflows, when a + multi-byte delimiter matches fewer bytes than specified. This was seen on + systems with invalid encoding configurations. E.g. glibc with CP1255. + [bug introduced in coreutils-9.9] + 'od' now exits gracefully when offsets overflow integer limits. [This bug was present in "the beginning".] diff --git a/tests/local.mk b/tests/local.mk index 0c0aa0ee5..f74215da3 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -428,6 +428,7 @@ all_tests = \ tests/nproc/nproc-positive.sh \ tests/nproc/nproc-override.sh \ tests/numfmt/numfmt.pl \ + tests/numfmt/mb-delim-len.sh \ tests/numfmt/mb-non-utf8.sh \ tests/misc/option-aliases.sh \ tests/od/od-N.sh \ diff --git a/tests/numfmt/mb-delim-len.sh b/tests/numfmt/mb-delim-len.sh new file mode 100755 index 000000000..77a70e706 --- /dev/null +++ b/tests/numfmt/mb-delim-len.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# Test delimiters matching fewer bytes than the delimiter specified + +# Copyright (C) 2026 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ numfmt printf + +tested=0 + +# With glibc, MB_CUR_MAX is 1 in CP1255, but 0xE9 0xC4 (yod, hiriq) +# is converted to a single character. https://sourceware.org/PR35092 +# With MB_CUR_MAX==1 we'll skip, otherwise ensure we process correctly. +export LC_ALL=yi_US +yod=$(env printf '\351') +delim=$(env printf '\351\304') +if test "$(locale charmap 2>/dev/null)" = CP1255 \ + && numfmt -d "$delim" </dev/null; then + tested=1 + + num_out=$(numfmt --from=si --field=2 -d "$delim" "1${delim}2K") + test "$num_out" = "1${delim}2000" || fail=1 + + # The first byte alone is not the delimiter. + # Previously numfmt would process memory beyond the trailing yod. + num_out=$(numfmt --field=2 -d "$delim" "1$yod" "2$yod") + test "$num_out" = "$(printf '%s\n' "1$yod" "2$yod")" || fail=1 + num_out=$(numfmt --from=si --field=2 -d "$delim" "${yod}x${delim}2K") + test "$num_out" = "${yod}x${delim}2000" || fail=1 +fi + +test "$tested" = 1 || skip_ 'CP1255 delimiters not supported' + +Exit $fail -- 2.56.0
