]> git.ipfire.org Git - thirdparty/coreutils.git/commit
wc: fix out-of-bounds read for single-byte wide characters master
authoraizu-m <aizumusheer2@gmail.com>
Fri, 19 Jun 2026 06:53:03 +0000 (12:23 +0530)
committerPádraig Brady <P@draigBrady.com>
Fri, 19 Jun 2026 14:39:10 +0000 (15:39 +0100)
commit6a850b9aacf82d83a46cd9a7fa551df834ab0b64
tree27cd47a524ff589b8ef6f236537d5117dacd61c2
parent04b757da79f59b7fc089e542acf32a5597d3d8bc
wc: fix out-of-bounds read for single-byte wide characters

In legacy CJK locales a single input byte can decode to a wide character
above UCHAR_MAX, e.g. SHIFT-JIS bytes 0xA1..0xDF become U+FF61..U+FF9F.
wc then indexed its 256-entry wc_isprint/wc_isspace tables with that
value and read past their end.
* src/wc.c (wc): Take the byte-indexed fast path only when the decoded
character fits in a byte; wider values fall through to c32width and
c32isspace.
* tests/wc/wc-sjis.sh: New test.
* tests/local.mk (all_tests): Add it.
* NEWS: Mention the fix.

Link: https://github.com/coreutils/coreutils/pull/298
NEWS
src/wc.c
tests/local.mk
tests/wc/wc-sjis.sh [new file with mode: 0755]