ZstdDecompressor.copy_stream() crashes when the source's read() returns str

Offen
#375 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 3 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
Ein halber Tag
Anfängerfreundlichkeit
55/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
c, python
Bereich
data

Rechercherichtung

The crash is in ZstdDecompressor.copy_stream(), the method on the decompressor class in the C extension. Run the reproducer first to confirm the SIGSEGV, then look at where the value returned by the source's read() is used without a bytes type check. Done means the reproducer raises TypeError instead of crashing, and a regression test covers a text-returning source.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

If the source passed to copy_stream() returns str instead of bytes from read(), e.g., a file opened in text mode, the interpreter crashes with SIGSEGV instead of raising TypeError.

Environment

  • zstandard 0.25.0
  • Python 3.13.5

Reproducer

import io

import zstandard

class Source:
    def __init__(self, chunk):
        self.chunks = [chunk]

    def read(self, size):
        return self.chunks.pop() if self.chunks else b""

zstandard.ZstdDecompressor().copy_stream(Source("data"), io.BytesIO())
Segmentation fault (core dumped)
Vorherrschende Sprache
C
Sterne
645
Forks
124
Ø Merge
2 T. 20 Std.
Gemergte PRs (30 T.)
8

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus indygreg/python-zstandard

Alle Issues in indygreg/python-zstandard

Ähnliche Issues

Weitere Issues zu C

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.