Skip to content

Back-references are rejected in byte (C locale) mode #543

Description

@sylvestre

Found by the differential fuzzer (fuzz/fuzz_targets/fuzz_sed.rs).

In the C/POSIX locale we select the byte-oriented engine, which rejects
back-references outright. GNU sed supports them in every locale.

$ printf 'aba\n' | LC_ALL=C sed -n '/\(a\)b\1/p'
aba
$ printf 'aba\n' | LC_ALL=C ./target/release/sed -n '/\(a\)b\1/p'
sed: <script argument 1>:1:11: error: invalid regex '(a)b(?:\1)': back-references are not supported in byte mode
# Exit code: 1

The same script works in a UTF-8 locale, so this only affects byte mode:

$ printf 'aba\n' | LC_ALL=en_US.UTF-8 ./target/release/sed -n '/\(a\)b\1/p'
aba

The error comes from src/sed/fast_regex.rs. Until this is fixed the fuzzer
skips scripts using back-references; see KNOWN_ISSUES in
fuzz/fuzz_targets/fuzz_sed.rs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions