@ -70,13 +70,28 @@ public partial class PngDecoderTests
WriteChunk ( memStream , chunkName ) ;
WriteChunk ( memStream , chunkName ) ;
WriteDataChunk ( memStream ) ;
WriteDataChunk ( memStream ) ;
ImageForma tException exception =
InvalidImageConten tException exception =
Assert . Throws < InvalidImageContentException > ( ( ) = > PngDecoder . Instance . Decode < Rgb24 > ( DecoderOptions . Default , memStream ) ) ;
Assert . Throws < InvalidImageContentException > ( ( ) = > PngDecoder . Instance . Decode < Rgb24 > ( DecoderOptions . Default , memStream ) ) ;
Assert . Equal ( $"CRC Error. PNG {chunkName} chunk is corrupt!" , exception . Message ) ;
Assert . Equal ( $"CRC Error. PNG {chunkName} chunk is corrupt!" , exception . Message ) ;
}
}
}
}
// https://github.com/SixLabors/ImageSharp/issues/3078
[Fact]
public void Decode_TruncatedPhysChunk_ExceptionIsThrown ( )
{
// 24 bytes — PNG signature + truncated pHYs chunk
byte [ ] payload = Convert . FromHexString (
"89504e470d0a1a0a3030303070485973" +
"3030303030303030" ) ;
using MemoryStream stream = new ( payload ) ;
InvalidImageContentException exception = Assert . Throws < InvalidImageContentException > ( ( ) = > Image . Load < Rgba32 > ( stream ) ) ;
Assert . Equal ( "pHYs chunk is too short" , exception . Message ) ;
}
private static string GetChunkTypeName ( uint value )
private static string GetChunkTypeName ( uint value )
{
{
byte [ ] data = new byte [ 4 ] ;
byte [ ] data = new byte [ 4 ] ;