MagickImage.ReadAsync swallows non cancellation related exceptions from the stream it reads from
まだ誰も着手していません。
評価
調査の方向性
まず、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
- 主要言語
- C#
- スター
- 4k
- フォーク
- 453
- 平均マージ
- 12時間 54分
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dlemstra/Magick.NET のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
dlemstra/Magick.NET#2087 · コメント 2 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
dlemstra/Magick.NET#2100 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
dlemstra/Magick.NET#2098 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
dlemstra/Magick.NET#2042 · コメント 4 件 ·
-
GPU supportオープン
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
dlemstra/Magick.NET#1949 · コメント 5 件 ·
dlemstra/Magick.NET の issue をすべて見る
似ている issue
-
A numeric literal is parsed in the host's culture, so 1.5 is 15 in a made EXE on a comma-decimal OSオープンbug interpreter silently-wrong small
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
reactiveui/ReactiveUI.Binding.SourceGenerators#176 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
dotnet/csharpstandard#1830 ·
メンテナーはふだん 1 日以内に返信
-
c:docs p:high size:S t:docs
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信