Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Unexpected crashes in SetData method of ExtendedUnixData

オープン
#887 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
csharp
領域
tooling

調査の方向性

src/ICSharpCode.SharpZipLib/Zip/ZipExtraData.cs の ExtendedUnixData.SetData から始め、次に issue にある count がゼロの場合と index が count に等しい場合の 2 つの再現テストケースを使用します。両方のケースで例外が発生しなくなり、メソッドが空の入力を no-op として処理するか、そのアプローチを選択する場合は制約を文書化すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

*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

主要言語
C#
スター
3.9k
フォーク
1k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

icsharpcode/SharpZipLib のほかの issue

icsharpcode/SharpZipLib の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。