MagickImage.ReadAsync swallows non cancellation related exceptions from the stream it reads from
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
Direzione di ricerca
Inizia individuando AsyncStreamWrapper.ReadAsync e il percorso di MagickImage.ReadAsync che lo attende. Riproduci il problema con il test ThrowingStream fornito, quindi verifica che la relativa IOException raggiunga il chiamante mentre la cancellazione continui a comportarsi come previsto. Il lavoro è completato quando il test passa senza restituire un’immagine vuota.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- C#
- Stelle
- 4k
- Fork
- 453
- Merge medio
- 12h 54m
- PR unite (30g)
- 3
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di dlemstra/Magick.NET
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
dlemstra/Magick.NET#2087 · 2 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
dlemstra/Magick.NET#2098 ·
-
Incorrect ExifIfds for ImageHistory exif tag (or conversion issue from System.Drawing.Bitmap)Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
dlemstra/Magick.NET#2042 · 4 commenti ·
-
GPU supportAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
dlemstra/Magick.NET#1949 · 5 commenti ·
-
x3f image read errAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
dlemstra/Magick.NET#1936 · 1 commento ·
Tutte le issue di dlemstra/Magick.NET
Issue simili
-
area:jobads-cv BE mvp P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
klasolsson81/jobbliggaren#2099 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
0 - Backlog Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
BrighterCommand/Brighter#4581 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
Esri/calcite-dotnet-toolkit#30 · 1 reazione ·
-
kind:docs simplification size:S status:todo
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
elsa-workflows/elsa-foundation#2604 ·
I maintainer di solito rispondono entro 1 giorno