File tree Expand file tree Collapse file tree 3 files changed +14
-20
lines changed
src/ImageSharp/Formats/Icon Expand file tree Collapse file tree 3 files changed +14
-20
lines changed 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)
175
175
Span < byte > buffer = stackalloc byte [ IconDirEntry . Size ] ;
176
176
177
177
// ICONDIR
178
- _ = IconAssert . EndOfStream ( stream . Read ( buffer [ ..IconDir . Size ] ) , IconDir . Size ) ;
178
+ _ = CheckEndOfStream ( stream . Read ( buffer [ ..IconDir . Size ] ) , IconDir . Size ) ;
179
179
this . fileHeader = IconDir . Parse ( buffer ) ;
180
180
181
181
// ICONDIRENTRY
182
182
this . entries = new IconDirEntry [ this . fileHeader . Count ] ;
183
183
for ( int i = 0 ; i < this . entries . Length ; i ++ )
184
184
{
185
- _ = IconAssert . EndOfStream ( stream . Read ( buffer [ ..IconDirEntry . Size ] ) , IconDirEntry . Size ) ;
185
+ _ = CheckEndOfStream ( stream . Read ( buffer [ ..IconDirEntry . Size ] ) , IconDirEntry . Size ) ;
186
186
this . entries [ i ] = IconDirEntry . Parse ( buffer ) ;
187
187
}
188
188
@@ -232,4 +232,14 @@ private IImageDecoderInternals GetDecoder(bool isPng)
232
232
UseDoubleHeight = true ,
233
233
} ) ;
234
234
}
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
+ }
235
245
}
Original file line number Diff line number Diff line change @@ -90,7 +90,8 @@ public void Encode<TPixel>(
90
90
// Only 32bit Png supported.
91
91
// https://devblogs.microsoft.com/oldnewthing/20101022-00/?p=12473
92
92
BitDepth = PngBitDepth . Bit8 ,
93
- ColorType = PngColorType . RgbWithAlpha
93
+ ColorType = PngColorType . RgbWithAlpha ,
94
+ CompressionLevel = PngCompressionLevel . BestCompression
94
95
} ,
95
96
_ => throw new NotSupportedException ( ) ,
96
97
} ;
You can’t perform that action at this time.
0 commit comments