Unexpected crashes in SetData method of ExtendedUnixData
まだ誰も着手していません。
評価
調査の方向性
src/ICSharpCode.SharpZipLib/Zip/ZipExtraData.cs の ExtendedUnixData.SetData から始め、次に issue にある count がゼロの場合と index が count に等しい場合の 2 つの再現テストケースを使用します。両方のケースで例外が発生しなくなり、メソッドが空の入力を no-op として処理するか、そのアプローチを選択する場合は制約を文書化すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- C#
- スター
- 3.9k
- フォーク
- 1k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
icsharpcode/SharpZipLib のほかの issue
-
*no response* bug
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
icsharpcode/SharpZipLib#905 · コメント 1 件 ·
-
bug bzip2
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
icsharpcode/SharpZipLib#904 ·
-
SetLevel in ZipFileオープンenhancement zip
難易度 2/5 1〜2日 初心者へのやさしさ 55/100
icsharpcode/SharpZipLib#903 ·
-
*no response* bug
難易度 4/5 3〜5日 初心者へのやさしさ 32/100
icsharpcode/SharpZipLib#901 · コメント 1 件 ·
-
*no response* bug
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
icsharpcode/SharpZipLib#894 · コメント 1 件 ·
icsharpcode/SharpZipLib の issue をすべて見る
似ている issue
-
area-System.Numerics.Tensors untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dotnet/runtime#134691 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
ci-failure-cause test-failure
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
AvaloniaUI/Avalonia#22312 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 68/100