diff panics on an oversized inline context count (`-c`/`-u`/`-C`/`-U`): parse overflow and capacity overflow

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

还没有人认领这个 Issue。

评估

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

调研方向

从 src/params.rs 中第279行和第323行附近的 parse_params 位置开始,然后复现 issue 中过大的 -c 和 -u 命令。检查现有的参数解析以及附近的测试或测试约定。完成的标准是:过大的上下文数量不再触发 panic,并且 diff 以正常输出和退出状态1完成,与报告的 GNU diff 行为一致。

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

描述

Summary

diff with an inline numeric context count whose digits exceed usize::MAX — e.g. -u99999999999999999999, -c99999999999999999999, --context=…, --unified=…, -C…, -U… — panics and aborts (exit 134). The option parser captures the digit run with a regex, then does numvalue.as_str().parse::<usize>().unwrap(); an out-of-range value makes parse return Err(PosOverflow) and the bare .unwrap() aborts. GNU diff accepts the oversized count (clamps it) and produces the diff normally, exit 1.

Steps to reproduce

$ printf 'a\n' > f1; printf 'b\n' > f2
$ diffutils diff -u99999999999999999999 f1 f2
thread 'main' panicked at src/params.rs:323:73:
called `Result::unwrap()` on an `Err` value: ParseIntError { kind: PosOverflow }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Aborted (core dumped)
$ echo $?
134

The context (-c/-C/--context) forms hit the sibling site src/params.rs:279:

$ diffutils diff -c99999999999999999999 f1 f2
thread 'main' panicked at src/params.rs:279:73:
called `Result::unwrap()` on an `Err` value: ParseIntError { kind: PosOverflow }
$ echo $?
134

Root cause

parse_params in src/params.rs captures the count with a regex \d+/\d*
that does not bound the digit-run length, then unwraps the parse:

// src/params.rs:279 (context) and :323 (unified)
let context = numvalue.as_str().parse::<usize>().unwrap();

A digit string larger than usize::MAX (e.g. 99999999999999999999) parses to Err(ParseIntError { kind: PosOverflow }), and the unconditional .unwrap() aborts.

Found by our static analysis tooling.

主要语言
Rust
星标
276
派生
39
平均合并
3 小时 27 分钟
30 天内合并 PR
3

贡献指南

打开贡献指南

从这里开始

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

uutils/diffutils 的其他 Issue

查看 uutils/diffutils 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

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