sed - output already produced is lost when a runtime error stops processing
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
src/sed/processor.rs の process_all_files と process_file を読み、出力がフラッシュされる前にエラーがどのように返されるかに注目してください。提供された test_output_kept_on_runtime_error のケースで再現し、実行時エラーの後にテストが one\ntwo\n を取得することを確認してください。以前の行のバッファー済み出力が保持され、コマンドが引き続き失敗を報告すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
When sed stops with a runtime error partway through its input, GNU sed has already written the
output for the earlier lines. uutils sed loses it when it reads a file operand and stdout is not
a terminal (a file or a pipe): everything still in the output buffer is dropped.
(The scanner report also mentions w files losing data when the script has a backward branch
loop; that part did not reproduce on current main, so it is left out.)
Reproduction
$ printf 'a\nb\nc\n' > in3
Rust (incorrect)
$ ./target/release/sed '3s//X/' in3 > out.txt; echo "rc=$?"; cat out.txt
sed: <script argument 1>:1:1: 'in3':3 error: no previous regular expression
rc=2
# out.txt is empty
GNU (correct)
$ /usr/bin/sed '3s//X/' in3 > out.txt; echo "rc=$?"; cat out.txt
/usr/bin/sed: -e expression #1, char 0: no previous regular expression
rc=1
a
b
(The exit status and message format also differ; those are separate issues. This one is only
about the lost a and b.)
Root cause
process_all_files in src/sed/processor.rs returns as soon as process_file fails
(src/sed/processor.rs:1005), so the output buffer for the current file is never flushed (nor
is named_writer::flush_all() at src/sed/processor.rs:1025-1026 reached):
context.input_name = path;
process_file(commands.clone(), &mut reader, output, context)?;
...
// Flush all output files
named_writer::flush_all()?;
Test
#[test]
fn test_output_kept_on_runtime_error() {
let temp_dir = assert_fs::TempDir::new().unwrap();
let input = temp_dir.child("in");
input.write_str("one\ntwo\nthree\n").unwrap();
new_ucmd!()
.args(&["3s//X/", input.path().to_str().unwrap()])
.fails()
.stdout_is("one\ntwo\n");
}
The output is lost with a pipe as well as with a file (sed '3s//X/' in3 | cat prints nothing),
so the default uutests capture should show the bug.
Reported by Anthropic's OSS Scanner (ANT-2026-D6QYNXKH).
- 主要言語
- Rust
- スター
- 123
- フォーク
- 53
- 平均マージ
- 2日 8時間
- マージ済み PR(30日)
- 40
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
uutils/sed のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
sed - with `--posix`, `-e 'i\'` takes the next `-e` as its text対応中かも @yunusarda-sudo が 14 日前に担当しました。 オープンbug gnu-compat good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
sed - script parser skips CR, VT, FF (and 0x85, 0xA0) as blanks; GNU skips only space and tab対応中かも @Himanshu-singh04 が 22 日前に担当しました。 オープンbug gnu-compat good first issue oss-scanner
難易度 2/5 1〜3時間 初心者へのやさしさ 89/100
メンテナーはふだん 1 日以内に返信
-
sed - with `-s` or `-i`, the file read by `R` is not restarted for each input file対応中かも @Himanshu-singh04 が 22 日前に担当しました。 オープンbug gnu-compat good first issue oss-scanner
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
sed - unknown POSIX class names like `[[:foo:]]` or `[[:word:]]` are accepted instead of rejected対応中かも @draarivpatel-ui が 7 日前に担当しました。 オープンbug gnu-compat good first issue oss-scanner
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
autofix:working
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
libracoder/kiri#1138 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
roc-lang/basic-webserver#277 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
samkerrcode/opengent#113 ·
メンテナーはふだん 1 日以内に返信
-
app bug session
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信