`ZstdCompressionWriter()` constructs successfully but leads to `segmentation fault`
Los mantenedores suelen responder en 4 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 76/100
Línea de trabajo
Ejecuta primero el reproductor de Python y luego inspecciona c-ext/compressionwriter.c:64 y c-ext/decompressionwriter.c:50 junto con las rutas de construcción del writer. Compara el comportamiento de la extensión de C con el backend de CFFI para la construcción sin argumentos. La tarea estará terminada cuando la construcción directa ya no deje campos internos NULL accesibles y lance una excepción de Python en lugar de provocar un segfault.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I've been fuzzing Python C extension modules for a small research project.
I found a sanitizer issue which is a null-pointer dereference in ZstdCompressionWriter_memory_size.
I reproduced it with the binary wheel from a plain pip install zstandard.
The process terminates with SIGSEGV there as well.
I'm not sure whether zero-argument construction of this type is considered supported (calling ZstdCompressionWriter() with no arguments),
but since it currently terminates the interpreter rather than raising a Python exception, I thought it was worth reporting.
Versions
zstandard 0.25.0, cext backend, CPython 3.12, Linux x86_64.
Reproducer
import zstandard
w = zstandard.ZstdCompressionWriter() # succeeds
w.memory_size() # SIGSEGV
Five calls across the two writer types behave the same way, each from a fresh direct construction:
| class | methods that segfault |
|---|---|
ZstdCompressionWriter |
memory_size(), close(), flush() |
ZstdDecompressionWriter |
memory_size(), flush() |
Sanitizer build
Same call, zstandard built with -fsanitize=address,undefined:
c-ext/compressionwriter.c:64:65: runtime error:
member access within null pointer of type 'ZstdCompressor'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
c-ext/compressionwriter.c:64:65
AddressSanitizer: SEGV on unknown address 0x000000000020
#0 ZstdCompressionWriter_memory_size c-ext/compressionwriter.c:64:65
ZstdDecompressionWriter.memory_size() reports the equivalent at
c-ext/decompressionwriter.c:50:67.
Expected behavior
I think that direct construction should be rejected with a Python exception, as it is by the CFFI backend.
Under PYTHON_ZSTANDARD_IMPORT_POLICY=cffi the same construction is refused outright:
TypeError: ZstdCompressionWriter.__init__() missing 5 required positional
arguments: 'compressor', 'writer', 'source_size', 'write_size',
and 'write_return_read'
Actual behavior
The C extension permits construction with no arguments, leaving internal fields NULL.
Several methods dereference those fields and terminate the process with SIGSEGV.
Although these objects are normally obtained through stream_writer(), I wonder whether the C extension should reject zero-argument construction, as the CFFI backend already does, rather than produce an uninitialized object.
- Lenguaje dominante
- C
- Estrellas
- 641
- Forks
- 117
- Merge medio
- 8 d 2 h
- PR fusionados (30 d)
- 7
Preparar el entorno
- 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 indygreg/python-zstandard
-
`multi_decompress_to_buffer([])` terminates the process with SIGFPEPosiblemente ocupada @mikamikasuki la tomó hace 9 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
indygreg/python-zstandard#335 ·
Los mantenedores suelen responder en 4 días
-
Silent data-correctness bug: `readinto()` / `readinto1()` on `stream_reader` return `tell() == 0` after successful readsPosiblemente ocupada @CAOShurong la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
indygreg/python-zstandard#295 ·
Los mantenedores suelen responder en 4 días
-
Python 3.15 wheelsAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 55/100
indygreg/python-zstandard#354 ·
Los mantenedores suelen responder en 4 días
-
Dificultad 3/5 1-2 días Aptitud para principiantes 64/100
indygreg/python-zstandard#345 ·
Los mantenedores suelen responder en 4 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 55/100
indygreg/python-zstandard#334 ·
Los mantenedores suelen responder en 4 días
Todos los issues de indygreg/python-zstandard
Issues similares
-
good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
Add `pdfcpu` to the pantryAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
bug good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
tmewett/BrogueCE#929 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug : find_key() compares kty against "ocy" instead of "oct", breaking kid-less HS256 verificationAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
OpenPrinting/cups#1756 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 76/100
SteamGridDB/SGDBoop#147 ·