GzipReader's encoding conversion behaves differently from IO

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

Maintainer antworten meist innerhalb von 2 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
25/100
Issue-Typ
Bug
Klarheit
Muss geklärt werden
Aktivitätsstatus
Aktiv
Tech-Stack
c, ruby
Bereich
backend

Rechercherichtung

This reports encoding-conversion mismatches between Zlib::GzipReader and IO, with three reproducible examples in the issue body. Start by finding where GzipReader applies external_encoding/internal_encoding in the C extension (ext/zlib/zlib.c) and compare with how io.c handles conversion errors and the gets limit. Note the maintainer is unsure whether fixing is desirable due to compatibility concerns, so the first step is discussing intended behavior before any patch; 'done' is a maintainer decision plus, if agreed, matching IO semantics with tests covering the three cases.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

When external_encoding/internal_encoding are given, Zlib::GzipReader converts the data differently from IO in a few ways. Fixing them could be incompatible, so I'm not sure whether they are worth fixing. I'm opening this issue for now.

  1. A conversion error is ignored, and the data is returned as is.

    # "a" in UTF-16BE followed by one extra byte
    gz = Zlib.gzip("\x00a\x00".b)
    o = {external_encoding: "UTF-16BE", internal_encoding: "UTF-8"}
    Zlib::GzipReader.new(StringIO.new(gz), **o).read
    #=> "\x00a\x00" (not converted)
    # IO#read raises Encoding::InvalidByteSequenceError
    

    With a dummy encoding such as UTF-16 (with BOM), getc returns "" and the extra byte is lost:

    gz = Zlib.gzip("\xFE\xFF\x00a\x00".b)
    o = {external_encoding: "UTF-16", internal_encoding: "UTF-8"}
    g = Zlib::GzipReader.new(StringIO.new(gz), **o)
    3.times.map { g.getc } #=> ["a", "", nil]
    
  2. The limit of gets is counted in bytes before conversion, while IO counts it after conversion.

    s = ("\x82\xa0" * 3 + "\n").b # "あああ\n" in Shift_JIS
    o = {external_encoding: "Shift_JIS", internal_encoding: "UTF-8"}
    Zlib::GzipReader.new(StringIO.new(Zlib.gzip(s)), **o).gets(3) #=> "ああ"
    # File#gets(3) with the same options returns "あ"
    
Vorherrschende Sprache
C
Sterne
73
Forks
43
Ø Merge
4 T. 18 Min.
Gemergte PRs (30 T.)
12

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

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 ruby/zlib

Alle Issues in ruby/zlib

Ähnliche Issues

Weitere Issues zu C

Neue Issues direkt in Ihr Postfach

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