wasip2: enabling O_APPEND with fcntl reuses the old positional output stream and overwrites the file
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 70/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- c, wasm
- Ambito
- backend, operating-systems
Direzione di ricerca
Start by reading libc-bottom-half/sources/file.c, especially file_fcntl_setfl() and the stream cleanup path in file_close_streams(). Run the supplied reproducer with both wasm32-wasip1 and wasm32-wasip2 using the listed wasi-sdk and wasmtime commands. Done when the P2 run appends Z to the initial file contents after F_SETFL enables O_APPEND, without the extra lseek().
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
wasip2: enabling O_APPEND with fcntl reuses the old positional output stream and overwrites the file
Summary
Calling fcntl(fd, F_SETFL, O_APPEND) on wasm32-wasip2 updates file->oflag but does not close the existing positional output stream. The next write therefore overwrites the previous position instead of appending to the end of the file.
Minimal reproducer
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main(void) {
char contents[32] = {0};
int fd = open("f", O_RDWR);
write(fd, "A", 1);
int flags = fcntl(fd, F_SETFL, O_APPEND);
write(fd, "Z", 1);
int in = open("f", O_RDONLY);
ssize_t size = read(in, contents, sizeof(contents) - 1);
printf("flags=%d size=%zd content=%s\n", flags, size, contents);
close(in);
close(fd);
return 0;
}
Use an initial file f containing abcdefghijklmnop, then compile and run with the same P1 and P2 commands:
/opt/wasi-sdk/bin/clang --target=wasm32-wasip1 -O2 repro.c -o repro-p1.wasm
/opt/wasi-sdk/bin/clang --target=wasm32-wasip2 -O2 repro.c -o repro-p2.wasm
wasmtime run --dir . repro-p1.wasm
wasmtime run --dir . repro-p2.wasm
Expected vs. actual output
Direct P1:
content=AbcdefghijklmnopZ
P2-libc:
content=AZcdefghijklmnop
Root cause
libc-bottom-half/sources/file.c:361-368 implements file_fcntl_setfl(). It updates the O_NONBLOCK and O_APPEND bits in file->oflag without calling file_close_streams().
The output stream was created before O_APPEND was enabled and remains in positional-write mode, so it writes Z at offset 1 rather than at EOF.
Suggested fix and causal validation
When the append bit changes, close the cached input/output streams (and associated pollables) so that the next write creates a stream using the new append mode.
The minimal patch produced:
- Unpatched: 3/3 executions generated
AZcdefghijklmnop. - Patched: 3/3 executions generated
AbcdefghijklmnopZ. - Reverted: 3/3 executions generated
AZcdefghijklmnop, and the revertedlibc.aSHA-256 matched the unpatched library.
Adding lseek(fd, 0, SEEK_SET) before the second write masks the problem because it closes the old stream; the short sequence without that extra operation exposes it directly.
- Lingua principale
- C
- Stelle
- 1k
- Fork
- 268
- Merge medio
- 1g 3h
- PR unite (30g)
- 20
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
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 WebAssembly/wasi-libc
-
wasip2/wasip3: reads never see data appended to a file after reaching EOFForse già presa @libsmol l’ha presa 25 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 61/100
WebAssembly/wasi-libc#889 ·
I maintainer di solito rispondono entro 1 giorno
-
Contradicting `SOL_TCP` and `SOL_UDP` definition for p1Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
WebAssembly/wasi-libc#855 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
WebAssembly/wasi-libc#815 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
WebAssembly/wasi-libc#809 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
WebAssembly/wasi-libc#778 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di WebAssembly/wasi-libc
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
OpenPrinting/cups#1826 ·
I maintainer di solito rispondono entro 1 giorno
-
Backport to 3.0 advertises a suffix that does not existForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
389ds/389-ds-base#8152 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
RetroAchievements/rcheevos#580 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
-
meta:feature-request
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
mpv-player/mpv#18855 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno