From 502274fc52cf1be0e08e4f80d1c9de1e657771b6 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Wed, 31 Jan 2024 22:29:49 +1100 Subject: [PATCH 1/2] Fix typo --- .../Exif/makernotes/OlympusCameraSettingsMakernoteDescriptor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MetadataExtractor/Formats/Exif/makernotes/OlympusCameraSettingsMakernoteDescriptor.cs b/MetadataExtractor/Formats/Exif/makernotes/OlympusCameraSettingsMakernoteDescriptor.cs index e61711690..4feef3f25 100644 --- a/MetadataExtractor/Formats/Exif/makernotes/OlympusCameraSettingsMakernoteDescriptor.cs +++ b/MetadataExtractor/Formats/Exif/makernotes/OlympusCameraSettingsMakernoteDescriptor.cs @@ -651,7 +651,7 @@ public sealed class OlympusCameraSettingsMakernoteDescriptor(OlympusCameraSettin if (Directory.GetObject(OlympusCameraSettingsMakernoteDirectory.TagGradation) is not short[] values || values.Length < 3) return null; - var ret = (values[0], values[1], values[3]) switch + var ret = (values[0], values[1], values[2]) switch { (0, 0, 0) => "n/a", (-1, -1, 1) => "Low Key", From 4d7253e17e27a01298667a333fabedb68820ecb7 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Wed, 31 Jan 2024 22:31:44 +1100 Subject: [PATCH 2/2] Avoid character substitution that Encoding.ASCII can perform --- .../QuickTime/QuickTimeReaderExtensions.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/MetadataExtractor/Formats/QuickTime/QuickTimeReaderExtensions.cs b/MetadataExtractor/Formats/QuickTime/QuickTimeReaderExtensions.cs index 4bba9909e..0068066cf 100644 --- a/MetadataExtractor/Formats/QuickTime/QuickTimeReaderExtensions.cs +++ b/MetadataExtractor/Formats/QuickTime/QuickTimeReaderExtensions.cs @@ -7,13 +7,33 @@ namespace MetadataExtractor.Formats.QuickTime /// public static class QuickTimeReaderExtensions { +#if NET462 || NETSTANDARD1_3 + public static unsafe string Get4ccString(this SequentialReader reader) +#else public static string Get4ccString(this SequentialReader reader) +#endif { + // https://en.wikipedia.org/wiki/FourCC + Span bytes = stackalloc byte[4]; + Span chars = stackalloc char[4]; reader.GetBytes(bytes); - return Encoding.ASCII.GetString(bytes); + // NOTE we cannot just use Encoding.ASCII here, as that can replace certain non-printable characters with '?' + chars[0] = (char)bytes[0]; + chars[1] = (char)bytes[1]; + chars[2] = (char)bytes[2]; + chars[3] = (char)bytes[3]; + +#if NET462 || NETSTANDARD1_3 + fixed (char* pChars = chars) + { + return new string(pChars, startIndex: 0, length: 4); + } +#else + return new string(chars); +#endif } public static decimal Get16BitFixedPoint(this SequentialReader reader)