Browse Source

Apply suggestions from code review

Co-authored-by: Günther Foidl <gue@korporal.at>
pull/2110/head
Brian Popow 4 years ago
committed by GitHub
parent
commit
b025d29de4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  2. 12
      src/ImageSharp/Formats/Png/PngEncoderCore.cs

2
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -1186,7 +1186,7 @@ namespace SixLabors.ImageSharp.Formats.Png
private void ReadColorProfileChunk(ImageMetadata metadata, ReadOnlySpan<byte> data)
{
int zeroIndex = data.IndexOf((byte)0);
if (zeroIndex < PngConstants.MinTextKeywordLength || zeroIndex > PngConstants.MaxTextKeywordLength)
if (zeroIndex is < PngConstants.MinTextKeywordLength or > PngConstants.MaxTextKeywordLength)
{
return;
}

12
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -694,11 +694,13 @@ namespace SixLabors.ImageSharp.Formats.Png
int bytesWritten = PngConstants.XmpKeyword.Length;
// Write the iTxt header (all zeros in this case).
payload[bytesWritten++] = 0;
payload[bytesWritten++] = 0;
payload[bytesWritten++] = 0;
payload[bytesWritten++] = 0;
payload[bytesWritten++] = 0;
Span<byte> iTxtHeader = payload.Slice(bytesWritten);
iTxtHeader[4] = 0;
iTxtHeader[3] = 0;
iTxtHeader[2] = 0;
iTxtHeader[1] = 0;
iTxtHeader[0] = 0;
bytesWritten += 5;
// And the XMP data itself.
xmpData.CopyTo(payload.Slice(bytesWritten));

Loading…
Cancel
Save