@@ -161,6 +161,31 @@ public void Decode_InternationalText_WithTruncatedDataAfterLanguageTag_DoesNotTh
161161 using Image < Rgba32 > image = Image . Load < Rgba32 > ( stream ) ;
162162 }
163163
164+ [ Fact ]
165+ public void Decode_tRnsChunk_WithAlphaLengthGreaterColorTableLength_ExceptionIsThrown ( )
166+ {
167+ byte [ ] payload = [ 137 , 80 , 78 , 71 , 13 , 10 , 26 , 10 , // PNG signature
168+ 0 , 0 , 0 , 13 , // chunk length 13 bytes
169+ 73 , 72 , 68 , 82 , // chunk type IHDR
170+ 0 , 0 , 0 , 1 , 0 , 0 , 0 , 1 , 8 , 3 , 0 , 0 , 0 , // data
171+ 40 , 203 , 52 , 187 , // crc
172+ 0 , 0 , 0 , 6 , // chunk length 6 bytes
173+ 80 , 76 , 84 , 69 , // chunk type palettte
174+ 255 , 0 , 0 , 0 , 255 , 0 , // data
175+ 210 , 135 , 239 , 113 , // crc
176+ 0 , 0 , 0 , 18 , // chunk length
177+ 116 , 82 , 78 , 83 , // chunk type tRns
178+ 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , // data
179+ 0 , 0 , 0 , 10 , // chunk length
180+ 73 , 68 , 65 , 84 , // chunk type data
181+ 120 , 156 , 99 , 96 , 0 , 0 , 0 , 2 , 0 , 1 , 72 , 175 , 164 , 113 ] ; // alpha.Length > colorTable.Length
182+
183+ using MemoryStream stream = new ( payload ) ;
184+ InvalidImageContentException exception = Assert . Throws < InvalidImageContentException > ( ( ) => Image . Load < Rgba32 > ( stream ) ) ;
185+
186+ Assert . Equal ( "The tRNS chunk contains more alpha values than there are palette entries." , exception . Message ) ;
187+ }
188+
164189 private static string GetChunkTypeName ( uint value )
165190 {
166191 byte [ ] data = new byte [ 4 ] ;
0 commit comments