Skip to content

Commit 7c0cd0b

Browse files
Merge separate assert file
1 parent 6beeba1 commit 7c0cd0b

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

src/ImageSharp/Formats/Icon/IconAssert.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/ImageSharp/Formats/Icon/IconDecoderCore.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

src/ImageSharp/Formats/Icon/IconEncoderCore.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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
};

0 commit comments

Comments
 (0)