You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
-w / \b treat non-ASCII bytes as word characters, unlike GNU in the C locale #64
grep - non-ASCII bytes are treated as word characters for -w/\b, unlike GNU in the C locale
Found by the differential fuzzer with args grep ["-e", "", "-F", "-w"] on input
lines containing non-ASCII bytes (e.g. 0xC3).
GNU grep run under LC_ALL=C classifies only ASCII [A-Za-z0-9_] as word-constituent
characters; every byte ≥ 0x80 is a non-word character. uu_grep decides word membership
with oniguruma's UTF-8 ONIGENC_CTYPE_WORD classifier, which counts Unicode letters/digits
(and any high byte it decodes) as word characters. This changes where word boundaries fall,
so -w (and the \b regex anchor) select different lines whenever the text around a match
contains a non-ASCII byte.
Reproduction
A word match r immediately followed by the byte 0xC3: GNU sees 0xC3 as a non-word
character, so r is a whole word and matches; uu_grep sees it as a word character, so the
right boundary fails and nothing matches.
The same divergence happens with a valid multi-byte UTF-8 letter such as é (0xC3 0xA9),
and with the \b regex anchor rather than -w:
$ printf'caf\xc3\xa9\n'| ./target/release/grep -w -F 'caf'# Rust: no match (exit 1)
$ printf'caf\xc3\xa9\n'| LC_ALL=C /usr/bin/grep -w -F 'caf'# GNU: matches "café" (exit 0)
$ printf'caf\xc3\xa9\n'| ./target/release/grep -a -o 'caf\b'# Rust: no match (exit 1)
$ printf'caf\xc3\xa9\n'| LC_ALL=C /usr/bin/grep -a -o 'caf\b'# GNU: matches "caf" (exit 0)
This is independent of the existing empty-pattern word/line report: here the pattern is a
non-empty literal and the difference is purely in how the adjacent character is classified.
The \b part is an inevitable problem with Oniguruma and I'm not sure what can be done about it, other that patching the library itself.
I assume that LC_ALL=C means that GNU grep treats files as ASCII as well. In that case we can just tell Oniguruma that both the Regex as well as the input file(s) are ASCII. All we have to do for that is stop hardcoding OnigEncodingUTF8.
Activity
Froloket64 commentedon Jun 28, 2026
There seem to be really two parts to this issue: related to
-wand related to\b.The
-wcan probably be worked around by adding an extra check:in
grep/src/matcher.rs
Line 124 in 670669e
The
\bpart is an inevitable problem with Oniguruma and I'm not sure what can be done about it, other that patching the library itself.lhecker commentedon Jul 20, 2026
I assume that
LC_ALL=Cmeans that GNU grep treats files as ASCII as well. In that case we can just tell Oniguruma that both the Regex as well as the input file(s) are ASCII. All we have to do for that is stop hardcodingOnigEncodingUTF8.