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

MagickImage.ReadAsync swallows non cancellation related exceptions from the stream it reads from

クローズ 初心者向け
#2,097 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

評価

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

調査の方向性

まず、AsyncStreamWrapper.ReadAsync と、それを待機する MagickImage.ReadAsync の経路を特定します。提供されている ThrowingStream テストで問題を再現し、その IOException が呼び出し元まで到達する一方で、キャンセルが意図したとおりに動作し続けることを確認します。テストが空の画像を返さずに成功すれば完了です。

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

説明

Magick.NET version

14.17.2

Environment (Operating system, version and so on)

Mac / Linix

Description

AsyncStreamWrapper has this code:

    private async Task ReadAsync(CancellationToken cancellationToken)
    {
        while (true)
        {
            try
            {
                await _performRead.WaitAsync(cancellationToken).ConfigureAwait(false);
            }
            catch
            {
                _exceptionThrown = true;
                if (_performRead.Wait(0))
                    _readDone.Release();
                return;
            }

            if (_readCount == -1)
                return;

            try
            {
                _readCount = await _stream.ReadAsync(Data, 0, _readCount, cancellationToken).ConfigureAwait(false);
            }
            catch
            {
                _exceptionThrown = true;
            }
            finally
            {
                _readDone.Release();
            }
        }
    }

if _stream.ReadAsync throws the fact is logged so that subsequently in the caller the cancellation token has an opportunity to throw.

        var readTask = ReadAsync(cancellationToken);

        await Task.WhenAll(actionTask, readTask).ConfigureAwait(false);

        if (_exceptionThrown)
            cancellationToken.ThrowIfCancellationRequested();
    }

However this has an unfortunate side effect, and that is that non-cancellation related exceptions are swallowed. I discovered this because I use a wrapper around my network streams that throw under certain conditions. When this wrapper throws MagickImage.ReadAsync returns an RGB image of 0x0 dimensions rather than allowing the exception to percolate up.

Steps to Reproduce
    class ThrowingStream : MemoryStream
    {
        public ThrowingStream(byte[] buffer, bool writable) : base(buffer, writable)
        {
        }

        public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
        {
            throw new IOException("Space Goat Failure");
        }
    }
    
    [TestMethod]
    public async Task SafeReadAsync_HealthyStream_ReadsTheImageBad()
    {
        using var image = new MagickImage();
        byte[] input = [1, 2, 3, 4, 5];

        await Assert.ThrowsAsync<Exception>(() => image.ReadAsync(new ThrowingStream(input, false)));
    }

The test fails because the exception is swallowed.

The screenshot is just a placeholder so I could submit the issue, it is of no relevance.

Images

Screenshot 2026-10-01 at 16.48.56.png

主要言語
C#
スター
4k
フォーク
453
平均マージ
12時間 54分
マージ済み PR(30日)
3

環境構築

はじめの一歩

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

dlemstra/Magick.NET のほかの issue

dlemstra/Magick.NET の issue をすべて見る

似ている issue

C# の issue をもっと見る

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

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