sed - output already produced is lost when a runtime error stops processing
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 86/100
Direzione di ricerca
Leggi process_all_files e process_file in src/sed/processor.rs, concentrandoti su come vengono restituiti gli errori prima che l'output venga svuotato. Riproduci il problema con il caso fornito test_output_kept_on_runtime_error e conferma che il test acquisisce one\ntwo\n dopo l'errore di runtime. Il lavoro è terminato quando l'output bufferizzato delle righe precedenti viene conservato e il comando continua a segnalare un errore.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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).
- Lingua principale
- Rust
- Stelle
- 123
- Fork
- 53
- Merge medio
- 2g 8h
- PR unite (30g)
- 40
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di uutils/sed
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
sed - with `--posix`, `-e 'i\'` takes the next `-e` as its textForse già presa @yunusarda-sudo l’ha presa 14 giorni fa. Apertabug gnu-compat good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
sed - script parser skips CR, VT, FF (and 0x85, 0xA0) as blanks; GNU skips only space and tabForse già presa @Himanshu-singh04 l’ha presa 22 giorni fa. Apertabug gnu-compat good first issue oss-scanner
Difficoltà 2/5 1-3 ore Idoneità per principianti 89/100
I maintainer di solito rispondono entro 1 giorno
-
sed - with `-s` or `-i`, the file read by `R` is not restarted for each input fileForse già presa @Himanshu-singh04 l’ha presa 22 giorni fa. Apertabug gnu-compat good first issue oss-scanner
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
sed - unknown POSIX class names like `[[:foo:]]` or `[[:word:]]` are accepted instead of rejectedForse già presa @draarivpatel-ui l’ha presa 7 giorni fa. Apertabug gnu-compat good first issue oss-scanner
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
autofix:working
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
libracoder/kiri#1138 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
roc-lang/basic-webserver#277 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
samkerrcode/opengent#113 ·
I maintainer di solito rispondono entro 1 giorno
-
app bug session
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno