-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore exceptions trying to read IPTC-IIM data #344
Open
StephenMcConnel
wants to merge
1
commit into
mono:main
Choose a base branch
from
StephenMcConnel:BL-11933-HandleUnknownIPTC
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+101
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using NUnit.Framework; | ||
using TagLib; | ||
using TagLib.IFD; | ||
using TagLib.IFD.Tags; | ||
using TagLib.IFD.Entries; | ||
using TagLib.Xmp; | ||
using TaglibSharp.Tests.Images.Validators; | ||
|
||
namespace TaglibSharp.Tests.Images | ||
{ | ||
public class BadIptcSectionTest | ||
{ | ||
[Test] | ||
public void Test () | ||
{ | ||
ImageTest.Run ("sample_IPTC_crash.jpg", | ||
false, | ||
new BadIptcSectionTestInvariantValidator (), | ||
NoModificationValidator.Instance, | ||
new PropertyModificationValidator<string> ("Copyright", null, "Copyright 2024 by Somebody Im Sure") | ||
); | ||
} | ||
} | ||
public class BadIptcSectionTestInvariantValidator : IMetadataInvariantValidator | ||
{ | ||
int calls = 0; | ||
public void ValidateMetadataInvariants (TagLib.Image.File file) | ||
{ | ||
// If we get here, the fix works. | ||
++calls; | ||
|
||
Assert.IsNotNull (file); | ||
|
||
Assert.IsFalse (file.PossiblyCorrupt); // The only problem is in the IPTC section, which we ignore. | ||
|
||
var tag = file.GetTag (TagTypes.TiffIFD) as IFDTag; | ||
Assert.IsNotNull (tag, "IFD tag not found"); | ||
|
||
var structure = tag.Structure; | ||
|
||
var exif = structure.GetEntry (0, (ushort)IFDEntryTag.ExifIFD) as SubIFDEntry; | ||
Assert.IsNotNull (exif, "Exif tag not found"); | ||
|
||
var exif_structure = exif.Structure; | ||
{ | ||
var entry = exif_structure.GetEntry (0, (ushort)ExifEntryTag.ExifVersion); | ||
Assert.IsNotNull (entry, "Entry 0x9000 missing in IFD 0"); | ||
Assert.IsNotNull (entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); | ||
var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; | ||
var bytes = new byte[] { 48, 50, 51, 49 }; | ||
Assert.AreEqual (bytes, parsed_bytes); | ||
} | ||
{ | ||
var entry = exif_structure.GetEntry (0, (ushort)ExifEntryTag.ColorSpace); | ||
Assert.IsNotNull (entry, "Entry 0xa001 missing in IFD 0"); | ||
Assert.IsNotNull (entry as ShortIFDEntry, "Entry is not a short IFD entry!"); | ||
var parsed_value = (entry as ShortIFDEntry).Value; | ||
Assert.AreEqual (65535, parsed_value); | ||
} | ||
{ | ||
var entry = exif_structure.GetEntry (0, (ushort)ExifEntryTag.PixelXDimension); | ||
Assert.IsNotNull (entry, "Entry 0xa001 missing in IFD 0"); | ||
Assert.IsNotNull (entry as LongIFDEntry, "Entry is not a long IFD entry!"); | ||
var parsed_value = (entry as LongIFDEntry).Value; | ||
Assert.AreEqual (4845, parsed_value); | ||
} | ||
{ | ||
var entry = exif_structure.GetEntry (0, (ushort)ExifEntryTag.PixelYDimension); | ||
Assert.IsNotNull (entry, "Entry 0xa001 missing in IFD 0"); | ||
Assert.IsNotNull (entry as LongIFDEntry, "Entry is not a long IFD entry!"); | ||
var parsed_value = (entry as LongIFDEntry).Value; | ||
Assert.AreEqual (2834, parsed_value); | ||
} | ||
|
||
|
||
var xmp = file.GetTag (TagTypes.XMP) as XmpTag; | ||
Assert.IsNotNull (xmp, "XMP tag not found"); | ||
|
||
Assert.AreEqual ("Adobe Photoshop 22.1 (Windows)", xmp.Software); | ||
// ValidateMetadataInvariants is called 3 times for each Validator: once in the | ||
// ParseUnmodifiedFile method, once in the ModifyFile method before changing | ||
// anything, and once in the ParseModifiedFile method. | ||
// The PropertyModificationValidator class verifies the property setting, but | ||
// I'm not sure I totally trust it, so I'm going to check the property value | ||
// here as well. | ||
if (calls == 1) | ||
Assert.IsNull (xmp.Copyright); | ||
if (xmp.Copyright != null) | ||
Assert.AreEqual ("Copyright 2024 by Somebody Im Sure", xmp.Copyright); | ||
Assert.IsNull (xmp.Creator); | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you sort these with System at the top. Also, there are a couple duplicates in this list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can fix this, I'm good with the changes and will merge them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, none of the System using statements were needed according to VS 2022, so I removed them along with the other redundant or otherwise unnecessary using statements.