Unexpected crashes in SetData method of ExtendedUnixData
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 55/100
Rechercherichtung
Beginne in src/ICSharpCode.SharpZipLib/Zip/ZipExtraData.cs bei ExtendedUnixData.SetData und verwende dann die beiden reproduzierenden Testfälle aus dem Issue für count gleich null und index gleich count. Fertig ist die Aufgabe, wenn beide Fälle keine Ausnahme mehr auslösen und die Methode leere Eingaben als No-op behandelt oder die Einschränkungen dokumentiert, falls dieser Ansatz gewählt wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Describe the bug
Hi :)
The SetData method in Zip/ZipExtraData.cs crashes with a System.IO.EndOfStreamException in two specific scenarios:
- when
countis set to 0 - when
indexis equal tocount
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
- Vorherrschende Sprache
- C#
- Sterne
- 3.9k
- Forks
- 1k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus icsharpcode/SharpZipLib
-
*no response* bug
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
icsharpcode/SharpZipLib#905 · 1 Kommentar ·
-
bug bzip2
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
icsharpcode/SharpZipLib#904 ·
-
SetLevel in ZipFileOffenenhancement zip
Schwierigkeit 2/5 1-2 Tage Anfängerfreundlichkeit 55/100
icsharpcode/SharpZipLib#903 ·
-
*no response* bug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 32/100
icsharpcode/SharpZipLib#901 · 1 Kommentar ·
-
*no response* bug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
icsharpcode/SharpZipLib#894 · 1 Kommentar ·
Alle Issues in icsharpcode/SharpZipLib
Ähnliche Issues
-
area-System.Numerics.Tensors untriaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
dotnet/runtime#134691 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
ci-failure-cause test-failure
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
AvaloniaUI/Avalonia#22312 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 68/100