Skip to content
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

Exception in ReadExifAPP1() due to duplicate keys when reading one particular image #80

Closed
davidebbo opened this issue Nov 29, 2020 · 5 comments

Comments

@davidebbo
Copy link

I have one jpeg image (apparently from some Windows Phone) where I get this exception when calling ImageFile.FromFile():

System.ArgumentException
  HResult=0x80070057
  Message=An item with the same key has already been added. Key: 384 (Parameter 'key')
  Source=System.Collections
  StackTrace:
   at System.Collections.Generic.SortedList`2.Add(TKey key, TValue value)
   at ExifLibrary.JPEGFile.ReadExifAPP1() in D:\Code\Github\exiflibrary\ExifLibrary\JPEGFile.cs:line 624
   at ExifLibrary.JPEGFile..ctor(MemoryStream stream, Encoding encoding, Boolean readTrailingData) in D:\Code\Github\exiflibrary\ExifLibrary\JPEGFile.cs:line 176
   at ExifLibrary.ImageFile.FromStreamInternal(MemoryStream stream, Encoding encoding) in D:\Code\Github\exiflibrary\ExifLibrary\ImageFile.cs:line 278
   at ExifLibrary.ImageFile.FromStream(Stream stream, Encoding encoding) in D:\Code\Github\exiflibrary\ExifLibrary\ImageFile.cs:line 175
   at ExifLibrary.ImageFile.FromFile(String filename, Encoding encoding) in D:\Code\Github\exiflibrary\ExifLibrary\ImageFile.cs:line 142
   at ExifLibrary.ImageFile.FromFile(String filename) in D:\Code\Github\exiflibrary\ExifLibrary\ImageFile.cs:line 129
   ...

I'm not familiar enough with the jpeg format to make sense of the code, but what I observe is that at the time of the exception, ifdqueue has 2 entries:

[0] -> [384, GPS]
[1] -> [562, First]

And then we try to insert a [384, Interop], which blows up because it already has the key 384.

If duplicates are expected, maybe the solution is to use a custom comparer that allows it, as in https://stackoverflow.com/a/21886340. Just a guess!

Awesome library by the way, I've used it successfully on many images!

@davidebbo
Copy link
Author

I tried the comparer implementation that allows duplicates from that SO question, and it makes the error go away. But I have no idea if that correct :)

@oozcitak
Copy link
Owner

Any chance you can attach the image?

@davidebbo
Copy link
Author

It's a kid picture so I'd rather not share publicly, but I can email it to you if you give me an address.

@oozcitak
Copy link
Owner

@davidebbo Thanks, I sent you an email.

@oozcitak
Copy link
Owner

oozcitak commented Dec 1, 2020

Fixed and released a new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants