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

Unexpected crashes in SetData method of ExtendedUnixData

Aperta
#887 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Inizia in src/ICSharpCode.SharpZipLib/Zip/ZipExtraData.cs, in ExtendedUnixData.SetData, quindi usa i due casi di test riproducibili dell’issue per count uguale a zero e index uguale a count. Il lavoro è completato quando entrambi i casi non generano più eccezioni e il metodo gestisce l’input vuoto come un’operazione no-op oppure documenta i vincoli se si sceglie questo approccio.

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

Descrizione

*no response* bug zip
Describe the bug

Hi :)

The SetData method in Zip/ZipExtraData.cs crashes with a System.IO.EndOfStreamException in two specific scenarios:

  • when count is set to 0
  • when index is equal to count

In both cases, the documentation does not indicate that these inputs are invalid.
I think, based on the documentation and signature, one would expect no operation to occur for these cases, as there is no data to process.

Steps to reproduce

The following two test cases can be used to demonstrate the behavior.
As of right now, they would both fail.

[Test]
public void SetDataCountZero()
{
    var extendedUnixData = new ExtendedUnixData();
    byte[] data = new byte[] { 1, 2, 3, 4 };
    int index = 0;
    int count = 0; // Nothing available to be read

    Assert.DoesNotThrow(() => extendedUnixData.SetData(data, index, count));
}

[Test]
public void SetDataOffsetAndCountEqual()
{
    var extendedUnixData = new ExtendedUnixData();
    byte[] data = new byte[] { 1, 2, 3, 4 };
    int index = 4;
    int count = 4;

    Assert.DoesNotThrow(() => extendedUnixData.SetData(data, index, count));
}
Expected behavior

I would expect the method to handle this gracefully and perform no operation.

I recommend that either,
1. the implementation is updated to handle these edge cases (e.g. return without reading from stream)

or

2. the documentation is adjusted to explicitly describe these constraints.

For 1., a simple check paired with an early return would do the trick:

/// <summary>
/// Set the data from the raw values provided.
/// </summary>
/// <param name = "data">The raw data to extract values from.</param>
/// <param name = "index">The index to start extracting values from.</param>
/// <param name = "count">The number of bytes available.</param>
public void SetData(byte[] data, int index, int count)
{
     if (count == 0 || index == count)
         return;

     using (MemoryStream ms = new MemoryStream(data, index, count, false))
     { ... }
}
Operating System

macOS

Framework Version

.NET 6

Tags

ZIP

Additional context

No response

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.