grep - interval counts above 32767 are accepted; GNU rejects them with `Regular expression too big`

未关闭 适合新手
#208 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@yunusarda-sudo 已经在做这个了。

开始于 2026年11月17日。

  • #218 来自 @yunusarda-sudo —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
79/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
cli

调研方向

首先追踪 uu_grep 如何解析 BRE 和 ERE 区间计数并将其传递给 Oniguruma;issue 指出 ONIG_MAX_REPEAT_NUM 是不一致的根源。为大于 32767 的计数和可接受的边界值添加覆盖,并参考复现案例和 GNU grep 的 bre 测试。完成标准是:超大边界值以退出码 2 和“Regular expression too big”报错,而 32767 仍被接受。

由索引模型根据 Issue 内容生成。

描述

bug gnu-compat good first issue

GNU grep accepts interval counts up to 32767 and rejects anything larger, in BRE and ERE and
for either bound, with Regular expression too big and exit 2 (observed with GNU grep 3.12:
k{32767} compiles, k{32768} does not). uu_grep passes the interval to Oniguruma, whose
own limit is 100000 (ONIG_MAX_REPEAT_NUM), so k{40000} and k{1,40000} are searched
and exit 0/1.

Exposed by the GNU test bre (Spencer BRE test #44, a\{32768\} must exit 2).

Reproduction

Rust (incorrect)

$ printf 'kk\n' | ./target/release/grep -E 'k{40000}'
# Output: (none)
# Exit code: 1

$ printf 'kk\n' | ./target/release/grep 'k\{40000\}'
# Output: (none)
# Exit code: 1

$ printf 'kk\n' | ./target/release/grep -E 'k{1,40000}'
kk
# Exit code: 0

GNU (correct)

$ printf 'kk\n' | LC_ALL=C /usr/bin/grep -E 'k{40000}'
/usr/bin/grep: Regular expression too big
# Exit code: 2

$ printf 'kk\n' | LC_ALL=C /usr/bin/grep 'k\{40000\}'
/usr/bin/grep: Regular expression too big
# Exit code: 2

$ printf 'kk\n' | LC_ALL=C /usr/bin/grep -E 'k{1,40000}'
/usr/bin/grep: Regular expression too big
# Exit code: 2

Test

#[test]
fn interval_count_limit() {
    for args in [
        &["-E", "w{32800}"][..],
        &["w\\{2,50000\\}"][..],
        &["-E", "w{,32768}"][..],
    ] {
        let (_s, mut c) = ucmd();
        c.args(args)
            .pipe_in("ww\n")
            .fails_with_code(2)
            .no_stdout()
            .stderr_contains("Regular expression too big");
    }
    // The largest accepted count still works.
    let (_s, mut c) = ucmd();
    c.args(&["-E", "-c", "w{32767}"])
        .pipe_in("ww\n")
        .fails_with_code(1)
        .stdout_only("0\n");
}

Exposed by the GNU grep test suite: bre.

主要语言
Rust
星标
147
派生
34
平均合并
3 天 18 小时
30 天内合并 PR
21

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

uutils/grep 的其他 Issue

查看 uutils/grep 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。