File tree Expand file tree Collapse file tree
src/ImageSharp/Formats/Icon Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -175,14 +175,14 @@ protected void ReadHeader(Stream stream)
175175 Span < byte > buffer = stackalloc byte [ IconDirEntry . Size ] ;
176176
177177 // ICONDIR
178- _ = IconAssert . EndOfStream ( stream . Read ( buffer [ ..IconDir . Size ] ) , IconDir . Size ) ;
178+ _ = CheckEndOfStream ( stream . Read ( buffer [ ..IconDir . Size ] ) , IconDir . Size ) ;
179179 this . fileHeader = IconDir . Parse ( buffer ) ;
180180
181181 // ICONDIRENTRY
182182 this . entries = new IconDirEntry [ this . fileHeader . Count ] ;
183183 for ( int i = 0 ; i < this . entries . Length ; i ++ )
184184 {
185- _ = IconAssert . EndOfStream ( stream . Read ( buffer [ ..IconDirEntry . Size ] ) , IconDirEntry . Size ) ;
185+ _ = CheckEndOfStream ( stream . Read ( buffer [ ..IconDirEntry . Size ] ) , IconDirEntry . Size ) ;
186186 this . entries [ i ] = IconDirEntry . Parse ( buffer ) ;
187187 }
188188
@@ -232,4 +232,14 @@ private IImageDecoderInternals GetDecoder(bool isPng)
232232 UseDoubleHeight = true ,
233233 } ) ;
234234 }
235+
236+ private static int CheckEndOfStream ( int v , int length )
237+ {
238+ if ( v != length )
239+ {
240+ throw new InvalidImageContentException ( "Not enough bytes to read icon header." ) ;
241+ }
242+
243+ return v ;
244+ }
235245}
Original file line number Diff line number Diff line change @@ -90,7 +90,8 @@ public void Encode<TPixel>(
9090 // Only 32bit Png supported.
9191 // https://devblogs.microsoft.com/oldnewthing/20101022-00/?p=12473
9292 BitDepth = PngBitDepth . Bit8 ,
93- ColorType = PngColorType . RgbWithAlpha
93+ ColorType = PngColorType . RgbWithAlpha ,
94+ CompressionLevel = PngCompressionLevel . BestCompression
9495 } ,
9596 _ => throw new NotSupportedException ( ) ,
9697 } ;
You can’t perform that action at this time.
0 commit comments