Skip to content

IPTC metadata: Fix an off-by-one error. #172

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

Merged
merged 1 commit into from
Apr 20, 2016

Conversation

cshclm
Copy link
Contributor

@cshclm cshclm commented Apr 20, 2016

Fixes an issue where a single-byte value at the end of an IPTC directory
would not be sufficient to consider the number of remaining bytes
sufficient, causing the extraction to be halted prematurely.

Fixes an issue where a single-byte value at the end of an IPTC directory
would not be sufficient to consider the number of remaining bytes
sufficient, causing the extraction to be halted prematurely.
// we need at least five bytes left to read a tag
if (offset + 5 >= length) {
// we need at least four bytes left to read a tag
if (offset + 4 >= length) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think the comment is correct. You need at least 5 bytes:

  • 1 for dir type
  • 1 for tag type
  • 2 for byte count
  • 1+ for contents

I don't think it's valid to have zero bytes of content.

Do you have an image that reproduces this behaviour? I can't quite make out the problem here.

@cshclm
Copy link
Contributor Author

cshclm commented Apr 20, 2016

Thanks, yes - here's an example:
https://drive.google.com/file/d/0B2n6vUzilT-TdVQ0S1VTcFFnYVU/view?usp=sharing

At the end of the IPTC directory of that file is an ObjectName tag with a single-byte value.
Without the change, its value will not be read (triggering "Too few bytes remain ...")
With the change, the tag is read successfully.

Currently, it would require the ObjectName tag in this example to have at least a 2-byte value. As best I can tell, the IPTC directory in that file is valid.

@drewnoakes
Copy link
Owner

Cheers. I'll take a look. Are you willing/able to donate that image to the project for regression testing?

@drewnoakes
Copy link
Owner

I think semantically the correct code is:

// we need at least five bytes left to read a tag
if (offset + 5 > length)

Thanks for finding this bug. Actually it occurs in two images in the test data set (Nikon D1X and Nikon D40) as well.

Your sample image is quite exotic, coming from a Maginon WK1. I had to Google that! Looks like a very cool camera, and now the image makes a bit more sense too.

@drewnoakes drewnoakes merged commit 594c933 into drewnoakes:master Apr 20, 2016
drewnoakes added a commit to drewnoakes/metadata-extractor-dotnet that referenced this pull request Apr 20, 2016
drewnoakes added a commit to drewnoakes/metadata-extractor-images that referenced this pull request Apr 20, 2016
@drewnoakes
Copy link
Owner

Just released this in 2.9.1.

@cshclm
Copy link
Contributor Author

cshclm commented Apr 21, 2016

Wow, thanks for the fast response!

For the regression test library, the owner would prefer a watermarked image be included. It sounds like you have this case covered already, though I'm happy to upload an example suitable for inclusion.

I did recognise the image was a bit out-there. For context, the Maginon camera (& metadata-extractor) is being used in wildlife conservation efforts in Vietnam.

Thanks again.

@drewnoakes
Copy link
Owner

Unfortunately watermarking images involves putting them through software. Software tends to do strange things to the metadata, and when an image has been processed via software I generally name it as coming from the software, rather than the camera. In this case I can reproduce the scenario in a unit test if the photographer is unwilling to offer a raw image for test data. Would be a shame. There's nothing commercial going on here, though my father's a professional photographer who watermarks everything online so I understand where they're coming from. I could give them credit in the commit log though, so it would be clear who provided the image.

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

Successfully merging this pull request may close these issues.

2 participants