od: --strings=0 reports stale offsets for empty strings

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

维护者通常 1 天内回复

已经有一个关联 PR 被合并了。

  • #16157 来自 @huuan26 —— 已合并

评估

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

调研方向

错误位于 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 内容生成。

描述

U - od

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

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

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

从这里开始

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

uutils/coreutils 的其他 Issue

查看 uutils/coreutils 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

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