shuf: exhausted random source destroys the input during an in-place shuffle
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
Línea de trabajo
Lee src/uu/shuf/src/shuf.rs, especialmente open_output() y el flujo de barajado en shuf_exec(). Después, inspecciona las pruebas de integración existentes de shuf y añade un caso de regresión para una fuente aleatoria agotada con salida en el mismo archivo. La tarea estará terminada cuando el comando informe del error de la fuente aleatoria, conserve la entrada y la prueba de regresión pase.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
An in-place shuffle with a readable but exhausted --random-source erases the input file before reporting the error. GNU shuf leaves the file unchanged.
Reproduced on Linux x86_64 at main c1f172886c6643f61ffde5a1ce3db0aaf14e182b, in debug and release builds. References: GNU 9.7 and the project-recommended GNU 9.12 package (9.12-0ubuntu1~ppa1).
Reproduce
From a built repository, using only disposable files:
d=$(mktemp -d)
printf 'one\ntwo\nthree\n' > "$d/input"
: > "$d/seed"
LC_ALL=C target/debug/coreutils shuf \
--random-source="$d/seed" -o "$d/input" "$d/input"
echo "status: $?"
wc -c < "$d/input"
Actual: "shuf: end of random source", exit 1, and input is now 0 bytes.
Expected: exit 1 with the original 14 bytes intact, as with GNU 9.7 and 9.12. Recreate the input before running the GNU comparison.
This also occurs with a nonempty but insufficient random source: 100 input records and a one-byte seed. It affects an existing separate output file and output paths that are hard links or symlinks to the input.
Cause and validation
In src/uu/shuf/src/shuf.rs, open_output() at line 164 calls File::create() before shuf_exec() draws random bytes. An EOF during the shuffle therefore happens after the output has been truncated. The syscall trace confirms O_TRUNC before the random-source EOF read.
Across 16 cases per binary (four random-source conditions and four output relationships), both GNU versions passed. Each uutils build lost data in all eight empty/short-source cases. Sufficient and missing-source controls passed. The existing shuf integration suite passes: 75 passed, 1 ignored.
Related: #13113 fixed truncation when input or random-source opening fails. This case successfully opens the random source and fails later while reading it. Searches of open/closed issues, PRs, and comments found no report of this remaining exhaustion case.
Please delay destructive output opening until the non-repeating shuffle has completed successfully, and add a regression test for random-source exhaustion with in-place output.
- Lenguaje dominante
- Rust
- Estrellas
- 24.3k
- Forks
- 2.1k
- Merge medio
- 1 d 21 h
- PR fusionados (30 d)
- 362
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de uutils/coreutils
-
ls: `--block-size=0` is accepted when `--si` comes laterPosiblemente ocupada @Logic769 la tomó hoy. Abiertogood first issue U - ls
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
B - high priority U - ln
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
uutils/coreutils#15980 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
uutils/coreutils#15962 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
B - high priority U - tr
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Los mantenedores suelen responder en 1 día
-
U - df
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
Todos los issues de uutils/coreutils
Issues similares
-
spurctld: a user with no usage gets a lower fair-share factor than a user with a little usageAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
area:ci kind:bug priority:p3 ready
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
tech-debt
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
srikanth235/centraid#1155 ·
Los mantenedores suelen responder en 1 día
-
dotfiles: failed batch untrack removes earlier tracking declarationsPosiblemente ocupada @jdx la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 2 días