Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

InflaterInputStream doesn't reset position of underlying stream to end of deflated data

Aperta
#584 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
csharp
Ambito
backend

Direzione di ricerca

Inizia da InflaterInputStream e dal suo punto di ingresso Read, quindi riproduci l’esempio con un file contenente dati finali per osservare come cambia la posizione del flusso sottostante. Il lavoro è completo quando, dopo la decompressione, il flusso sottostante si trova alla fine dei dati compressi, così la successiva lettura di 4 byte restituisce i dati finali invece dei byte memorizzati nel buffer.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Steps to reproduce
  1. Obtain a file that contains a deflated blob with some other data following it. In my case, I have a binary file where there is a deflated blob, followed by some additional ints/floats/etc. It's important that there is trailing data after the deflated blob. It doesn't matter what the data is, it could be garbage. It just has to exist. The code below assumes there is at least 4 bytes in this trailing data.
  2. Run this simple program against it, after filling in appropriate values for InFile, InFileCompressedDataStartPos, InFileCompressedLength, and InFileUncompressedLength:
    internal class Program
    {
        private static string InFile = @"";

        private static int InFileCompressedDataStart = 0;
        private static int InFileCompressedLength = 0;
        private static int InFileUncompressedLength = 0;
        
        public static void Main(string[] args)
        {
            using (var stream = File.OpenRead(InFile))
            {
                stream.Position = InFileCompressedDataStart;

                //Encounter deflated blob in stream, and inflate it
                using (var zStream = new InflaterInputStream(stream))
                {
                    zStream.IsStreamOwner = false;
                    var buffer = new byte[InFileUncompressedLength];

                    var streamStartPos = stream.Position;
                    Console.WriteLine($"Stream position before inflate: {streamStartPos}");

                    var read = zStream.Read(buffer, 0, InFileCompressedLength);
                    Console.WriteLine($"InflaterInputStream read {read} bytes");

                    var streamEndPos = stream.Position;
                    Console.WriteLine($"Stream position after inflate: {streamEndPos}");
                    Console.WriteLine($"Stream position moved {streamEndPos - streamStartPos} bytes during read");
                }

                //Continue on with data following deflated blob
                var testBuffer = new byte[4];
                stream.Read(testBuffer, 0, 4);    //This reads from the wrong offset in the file!
            }
        }
    }
  1. Note the console output
Expected behavior

stream.Position should have progressed by InFileCompressedLength. (to allow the trailing data to be read independently)

Actual behavior

stream.Position progressed by some amount greater than InFileCompressedLength. (this is part way thru completely unrelated data!)

Version of SharpZipLib

1.3.1

Obtained from (only keep the relevant lines)
  • Package installed using NuGet
Lingua principale
C#
Stelle
3.9k
Fork
1k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di icsharpcode/SharpZipLib

Tutte le issue di icsharpcode/SharpZipLib

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.