From 3ea2978b7b939304e6473920db4a51026cc7dc43 Mon Sep 17 00:00:00 2001 From: popow Date: Sat, 7 Jul 2018 13:30:19 +0200 Subject: [PATCH] if Exif data exceeds 64K and is split over multiple App1 marker, it will be extended like the ICC profile does --- .../Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs | 10 +++++++++- .../MetaData/Profiles/Exif/ExifProfile.cs | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs index bd1d84ecc9..8b5b7b151b 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs @@ -472,7 +472,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort if (ProfileResolver.IsProfile(profile, ProfileResolver.ExifMarker)) { this.isExif = true; - this.MetaData.ExifProfile = new ExifProfile(profile); + if (this.MetaData.ExifProfile == null) + { + this.MetaData.ExifProfile = new ExifProfile(profile); + } + else + { + // if the exif information exceeds 64K, it will be split over multiple APP1 marker + this.MetaData.ExifProfile.Extend(profile); + } } } diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs index b38097060e..1f2695c5e6 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; @@ -18,7 +17,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif /// /// The byte array to read the EXIF profile from. /// - private readonly byte[] data; + private byte[] data; /// /// The collection of EXIF values @@ -230,6 +229,19 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif this.values.Add(newExifValue); } + /// + /// Extends the profile with additional data. + /// + /// The array containing addition profile data. + public void Extend(byte[] bytes) + { + int currentLength = this.data.Length; + + // the first 6 bytes are Exif00 and will be skipped + Array.Resize(ref this.data, currentLength + bytes.Length - 6); + Buffer.BlockCopy(bytes, 6, this.data, currentLength, bytes.Length - 6); + } + /// /// Converts this instance to a byte array. ///