Browse Source

Use ASCII Encoding when known to be ASCII

af/merge-core
Jason Nelson 7 years ago
parent
commit
473a7f40ab
  1. 4
      src/ImageSharp/Formats/Gif/GifConstants.cs
  2. 8
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs
  3. 2
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  4. 2
      tests/ImageSharp.Tests/Formats/Png/PngChunkTypeTests.cs

4
src/ImageSharp/Formats/Gif/GifConstants.cs

@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <summary>
/// The ASCII encoded bytes used to identify the GIF file.
/// </summary>
internal static readonly byte[] MagicNumber = Encoding.UTF8.GetBytes(FileType + FileVersion);
internal static readonly byte[] MagicNumber = Encoding.ASCII.GetBytes(FileType + FileVersion);
/// <summary>
/// The extension block introducer <value>!</value>.
@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <summary>
/// The ASCII encoded application identification bytes.
/// </summary>
internal static readonly byte[] NetscapeApplicationIdentificationBytes = Encoding.UTF8.GetBytes(NetscapeApplicationIdentification);
internal static readonly byte[] NetscapeApplicationIdentificationBytes = Encoding.ASCII.GetBytes(NetscapeApplicationIdentification);
/// <summary>
/// The Netscape looping application sub block size.

8
src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs

@ -14,22 +14,22 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
/// <summary>
/// Describes the EXIF specific markers
/// </summary>
public static readonly byte[] JFifMarker = Encoding.UTF8.GetBytes("JFIF\0");
public static readonly byte[] JFifMarker = Encoding.ASCII.GetBytes("JFIF\0");
/// <summary>
/// Describes the EXIF specific markers
/// </summary>
public static readonly byte[] IccMarker = Encoding.UTF8.GetBytes("ICC_PROFILE\0");
public static readonly byte[] IccMarker = Encoding.ASCII.GetBytes("ICC_PROFILE\0");
/// <summary>
/// Describes the ICC specific markers
/// </summary>
public static readonly byte[] ExifMarker = Encoding.UTF8.GetBytes("Exif\0\0");
public static readonly byte[] ExifMarker = Encoding.ASCII.GetBytes("Exif\0\0");
/// <summary>
/// Describes Adobe specific markers <see href="http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JPEG.html#Adobe"/>
/// </summary>
public static readonly byte[] AdobeMarker = Encoding.UTF8.GetBytes("Adobe");
public static readonly byte[] AdobeMarker = Encoding.ASCII.GetBytes("Adobe");
/// <summary>
/// Returns a value indicating whether the passed bytes are a match to the profile identifier

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

@ -1005,7 +1005,7 @@ namespace SixLabors.ImageSharp.Formats.Png
if (this.crc.Value != chunk.Crc)
{
string chunkTypeName = Encoding.UTF8.GetString(chunkType);
string chunkTypeName = Encoding.ASCII.GetString(chunkType);
throw new ImageFormatException($"CRC Error. PNG {chunkTypeName} chunk is corrupt!");
}

2
tests/ImageSharp.Tests/Formats/Png/PngChunkTypeTests.cs

@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
private static PngChunkType GetType(string text)
{
return (PngChunkType)BinaryPrimitives.ReadInt32BigEndian(Encoding.UTF8.GetBytes(text));
return (PngChunkType)BinaryPrimitives.ReadInt32BigEndian(Encoding.ASCII.GetBytes(text));
}
}
}
Loading…
Cancel
Save