od: --strings=0 reports stale offsets for empty strings
维护者通常 1 天内回复
已经有一个关联 PR 被合并了。
- #16157 来自 @huuan26 —— 已合并
评估
调研方向
错误位于 src/uu/od/src/od.rs 中的 extract_strings_from_input(约第 659-668 行),其中 string_start_offset 只在读取到可打印字节时才更新,因此空字符串会沿用之前的偏移量。使用 issue 中的 printf | od --strings=0 -Ad 命令进行复现,然后检查现有的 od 字符串处理测试。当 NUL 之后的空字符串报告其自身的偏移量(示例中为字节 4,连续两个 NUL 时为 0 和 1),与 GNU 保持一致,并且 -j4 处理正确时,即完成。
由索引模型根据 Issue 内容生成。
描述
od --strings=0 prints the previous string's starting offset for an empty string. It can even report an offset before the position requested by --skip-bytes.
Reproduced on Linux x86_64 (Debian 13), with uutils 0.13.0 built from main at 43eb6205c20c551480057cdee98e6e7529cd984d. Compared with GNU coreutils 9.12 from the reference package linked in CONTRIBUTING.md and GNU 9.7.
From the repository root:
cargo build --locked -p uu_od
export LC_ALL=C LANG=C
printf 'abc\0\0def\0' | target/debug/od --strings=0 -Ad | cat -A
Actual output ($ marks line endings):
0000000 abc$
0000000 $
0000005 def$
Expected output (GNU 9.12 and 9.7):
0000000 abc$
0000004 $
0000005 def$
The empty string is at byte 4, not byte 0. Both implementations exit 0 with empty stderr.
Adding -j4 produces the same incorrect 0000000 for the first result, even though bytes 0–3 were skipped. Two consecutive NUL bytes also reproduce it: uutils reports offsets 0, 0; GNU reports 0, 1. Nonempty strings and -S1 behave correctly in the control cases.
In extract_strings_from_input, od.rs:659–668, string_start_offset is updated only when a printable byte is read. An empty string contains no such byte, so its output uses the stale offset.
No matching report was found in searches of open and closed issues and related PRs. #11613 concerns unterminated strings with -N, and #15592 concerns hexadecimal padding width; this case uses terminated strings, decimal offsets, and no -N.
- 主要语言
- Rust
- 星标
- 24.3k
- 派生
- 2.2k
- 平均合并
- 2 天 17 小时
- 30 天内合并 PR
- 422
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
uutils/coreutils 的其他 Issue
-
cp: fails to compile due to E0609 error可能已有人在做 @Devel08 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
pr: -o/--indent does not pad the header line可能已有人在做 @emirmrkaljevic 于 2 天前认领。 未关闭U - pr
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复
-
realpath: empty operand aborts with a garbled error instead of being reported as missing可能已有人在做 @emirmrkaljevic 于 2 天前认领。 未关闭U - realpath
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 半天 新手友好度 62/100
维护者通常 1 天内回复
-
nl: section delimiters reset --join-blank-lines grouping可能已有人在做 @coracoracora 于 3 天前认领。 未关闭U - nl
难度 2/5 1-3 小时 新手友好度 74/100
uutils/coreutils#16130 · 1 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
RustCrypto/utils#1597 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
max-sixty/worktrunk#4727 · 7 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复
-
follow-up
难度 2/5 1-3 小时 新手友好度 73/100
carrick-sh/carrick#1859 ·
维护者通常 1 天内回复