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

some [Canon] & [Composite] tags get lost or modified #1589

Closed
tenzap opened this issue Apr 26, 2021 · 19 comments
Closed

some [Canon] & [Composite] tags get lost or modified #1589

tenzap opened this issue Apr 26, 2021 · 19 comments
Assignees
Labels
bug makerNote Anything related to one of the various supported MakerNote formats wontfix
Milestone

Comments

@tenzap
Copy link

tenzap commented Apr 26, 2021

With linked canon pictures, some [Canon] & [Composite] tags get lost or modified when for example deleting thumbnail when running:

exiv2 -dt pic.jpg

Same problem when inserting thumbnail, and maybe whichever operation we do.

This is with 0.27.4 RC2

Sample pictures:

Report of diff using "exiftool -a -G1 pic.jpg" for one of the pictures above, the other picture has a different diff result

-[Canon]         AE Setting                      : Normal AE
-[Canon]         AEB Bracket Value               : 0
-[Canon]         AF Area Heights                 : 622 0 0 0 0 0 0 0 0
-[Canon]         AF Area Mode                    : Off (Manual Focus)
-[Canon]         AF Area Widths                  : 829 0 0 0 0 0 0 0 0
-[Canon]         AF Area X Positions             : 0 0 0 0 0 0 0 0 0
-[Canon]         AF Area Y Positions             : 0 0 0 0 0 0 0 0 0
-[Canon]         AF Image Height                 : 3456
-[Canon]         AF Image Width                  : 4608
-[Canon]         AF Points In Focus              : (none)
-[Canon]         Aspect Ratio                    : 4:3
-[Canon]         Auto Exposure Bracketing        : Off
-[Canon]         Auto ISO                        : 400
-[Canon]         Auto Rotate                     : Rotate 90 CW
-[Canon]         Base ISO                        : 200
-[Canon]         Bulb Duration                   : 0
-[Canon]         Camera ISO                      : Auto
-[Canon]         Camera Temperature              : 21 C
-[Canon]         Camera Type                     : Compact
-[Canon]         Canon Exposure Mode             : Program AE
-[Canon]         Canon Firmware Version          : Firmware Version 1.00
-[Canon]         Canon Flash Mode                : Off
-[Canon]         Canon Image Height              : 1536
-[Canon]         Canon Image Size                : Medium 2
-[Canon]         Canon Image Type                : IMG:PowerShot SX60 HS JPEG
-[Canon]         Canon Image Width               : 2048
+[Canon]         Aspect Ratio                    : 3:2
+[Canon]         Camera Temperature              : 0 C
+[Canon]         Canon Firmware Version          : 
+[Canon]         Canon Image Type                : 
 [Canon]         Canon Model ID                  : PowerShot SX60 HS
-[Canon]         Categories                      : (none)
-[Canon]         Continuous Drive                : Single
-[Canon]         Contrast                        : Normal
-[Canon]         Control Mode                    : Camera Local Control
-[Canon]         Cropped Image Height            : 3456
+[Canon]         Cropped Image Height            : 0
-[Canon]         Cropped Image Width             : 4608
+[Canon]         Cropped Image Width             : 0
 [Canon]         Date Stamp Mode                 : Off
-[Canon]         Daylight Savings                : Off
-[Canon]         Digital Zoom                    : None
-[Canon]         Easy Mode                       : Manual
-[Canon]         Exposure Compensation           : +1
-[Canon]         Exposure Time                   : 1/64
-[Canon]         F Number                        : 5.6
-[Canon]         Faces Detected                  : 0
 [Canon]         File Number                     : 102-0153
 [Canon]         Firmware Revision               : 1.00 rev 2.00
-[Canon]         Flash Activity                  : 0
-[Canon]         Flash Bits                      : (none)
-[Canon]         Flash Exposure Compensation     : 0
-[Canon]         Flash Guide Number              : 0
-[Canon]         Flash Output                    : 0
-[Canon]         Focal Units                     : 100/mm
-[Canon]         Focus Continuous                : Manual
-[Canon]         Focus Distance Lower            : 0 m
-[Canon]         Focus Distance Upper            : 65.53 m
-[Canon]         Focus Mode                      : Manual Focus (3)
-[Canon]         Focus Range                     : Manual
-[Canon]         Image Stabilization             : On (2)
-[Canon]         Image Unique ID                 : 54e8b2b5539347478841864f8be0dcc5
-[Canon]         Intelligent Contrast            : On (0x09)
-[Canon]         Lens Type                       : n/a
-[Canon]         Macro Mode                      : Normal
-[Canon]         Manual Flash Output             : n/a
-[Canon]         Max Aperture                    : 5.6
-[Canon]         Max Focal Length                : 247 mm
-[Canon]         Measured EV                     : 10.19
-[Canon]         Metering Mode                   : Evaluative
-[Canon]         Min Aperture                    : 8
-[Canon]         Min Focal Length                : 3.8 mm
-[Canon]         My Color Mode                   : Off
-[Canon]         ND Filter                       : Off
-[Canon]         Num AF Points                   : 9
-[Canon]         Optical Zoom Code               : 139
-[Canon]         Quality                         : Fine
-[Canon]         Record Mode                     : JPEG
-[Canon]         Saturation                      : Normal
-[Canon]         Self Timer                      : Off
-[Canon]         Self Timer 2                    : 0
-[Canon]         Sharpness                       : 0
-[Canon]         Shot Number In Continuous Burst : 0
-[Canon]         Slow Shutter                    : Off
-[Canon]         Spot Metering Mode              : Center
-[Canon]         Target Aperture                 : 5.6
-[Canon]         Target Exposure Time            : 1/60
+[Canon]         Image Unique ID                 : e7e976fa3c9347478841864f8be0dcc5
 [Canon]         Thumbnail Image Valid Area      : 0 0 0 0
-[Canon]         Time Zone                       : +01:00
-[Canon]         Time Zone City                  : (not set)
 [Canon]         VRD Offset                      : 0
-[Canon]         Valid AF Points                 : 1
-[Canon]         White Balance                   : Auto
-[Canon]         Zoom Source Width               : 4608
-[Canon]         Zoom Target Width               : 4608


-[Composite]     Depth Of Field                  : 21.75 m (25.17 - 46.92 m)
-[Composite]     Drive Mode                      : Single-frame Shooting
 [Composite]     Field Of View                   : 6.4 deg
 [Composite]     Focal Length                    : 57.0 mm (35 mm equivalent: 319.9 mm)
 [Composite]     Hyperfocal Distance             : 108.41 m
-[Composite]     ISO                             : 800
 [Composite]     Image Size                      : 2048x1536
-[Composite]     Lens                            : 3.8 - 247.0 mm (35 mm equivalent: 21.3 - 1385.8 mm)
-[Composite]     Lens                            : 3.8 - 247.0 mm
-[Composite]     Lens ID                         : Unknown 3-247mm
 [Composite]     Light Value                     : 7.9
 [Composite]     Megapixels                      : 3.1
 [Composite]     Scale Factor To 35 mm Equivalent: 5.6
-[Composite]     Shooting Mode                   : Program AE
@kmilos
Copy link
Collaborator

kmilos commented Apr 26, 2021

Just an FYI: ExifTool's "Composite" tags are derived/calculated from data, and not actually in the file, so not really relevant for the issue here.

@tenzap
Copy link
Author

tenzap commented Apr 26, 2021

Just an FYI: ExifTool's "Composite" tags are derived/calculated from data, and not actually in the file, so not really relevant for the issue here.

Oh ok, I didin't know that, thanks. So problem is with the Canon tags then.

@hassec hassec added the makerNote Anything related to one of the various supported MakerNote formats label May 14, 2021
@hassec hassec added the bug label May 25, 2021
@hassec
Copy link
Member

hassec commented May 25, 2021

It seems that exiv2 doesn't correctly handle the specific makernote in these files...
Which probably leads to exiv2 messing up the file when one runs exiv2 -dt

Sorry that I can't be more helpful yet.
Will have to do some more digging.

@hassec hassec added this to the v1.00 milestone May 25, 2021
@hassec
Copy link
Member

hassec commented May 25, 2021

@tenzap are the images you linked straight out of the camera or were they previously modified by some tool?

@tenzap
Copy link
Author

tenzap commented May 26, 2021

I don't know if they have been modified.
If I remember well the pictures are downscaled on that repo but the exif data is unchanged.

They have been contributed in that repo by
Contributed by: Jesus Cea <[email protected]>

See readme in https://github.com/ianare/exif-samples/tree/master/jpg/hdr

@tenzap
Copy link
Author

tenzap commented May 26, 2021

https://github.com/ianare/exif-samples/blob/master/jpg/README

@hassec
Copy link
Member

hassec commented May 26, 2021

Ok, so the good news are that I think I know the reason for the problem:

The offsets of the makernote IFDs are incorrect.
Apparently there are multiple things that can cause this... One of which is editing a file with software that doesn't properly handle these makernotes.

There is some documentation about this in the exiftool doc. (search for fixbase)

Now that we know this we can come up with a workaround, by simply using exiftool to fix the offsets.
It does so when we write an exif field.

To not actually change the content we do the following:

  1. Determine value of one field
$ exiftool -exif:resolutionunit tmp.jpg
> Resolution Unit                 : inches
  1. Overwrite with same value
$ exiftool -F -exif:resolutionunit=inches tmp.jpg

Now you can run exiv2 -dt on that file without exiv2 screwing up these files, and the reported canon tags are still there.

But the bad news: I don't know whether there is going to be an exiv2 only solution soon...
Technically the file is in a somewhat broken state, and exiftool seems to notice this and account for that.
Amazing job exiftool!! 🎉 💪
I'm new to this project and don't know if we want to go down the road of trying to "on the fly fix" files.
Just seems like a very open and never ending problem landscape...

@clanmills are you aware of similar problems in the past? Is this something that is common enough for us to make this urgent?
Also would love to hear @piponazo's opinion on this.

Maybe we will just leave this open and try to come up with a solution when the canon makernote gets modernized?

@clanmills
Copy link
Collaborator

clanmills commented Jun 11, 2021

The differences in the metadata between canon_hdr_NO.jpg and canon_hdr_YES.jpg are considerable. Changes have been made in [exifIFD] and [canon makernote]. However most of the data in both are untouched. I'm not convinced that the explanation is an incorrect offset to an IFD. If that were true, the data would be massively disturbed.

I haven't studied the claim that deleting the thumbnail causes collateral metadata damage.

A solid issue here is that ExifTool reports [Composite] tags which are calculated from other metadata by ExifTool and not by Exiv2. I don't think Exiv2 should get into the interpretation/manufacture of metadata and should report exactly what's in the file. If an application such as darktable believes [composite] values are important to photographers, they can calculate them and display them in their UI.

If darktable wants Exiv2 to calculate [composite] tags, they could raise an enhancement request for Exiv2 to support this. In 2019, I did manufacture tags using Canon AutoFocus data. #1001. With Exiv2 v1.00, we have the opportunity to modify the API and could add a "manufactured" field to TagInfo as such data requires careful handling during writeMetadata().

We're discussing about four different matters here, so the signal-to-noise ratio isn't good. We need an original camera file which is edited in a simple manner such as:

  1. Delete the the thumbnail (and nothing else)
  2. Change a single tag in the [exifIFD] such as Exif.Photo.DateTimeDigitized (and nothing else)
  3. Change a single maker note tag such as Exif.CanonCs.Timer (and nothing else)

I recommend that [Composite] tags be handled in the host application and not in the library as those tags are not in the image.

@hassec
Copy link
Member

hassec commented Jun 11, 2021

Thanks @clanmills for the comments 👍

@tenzap, for now at least, the problem of "fixing files on the fly" is out of scope for exiv2.
Thus, I'll go ahead and label this "wonfix" and close it.

Please feel free to reopen the issue if you'd like to further discuss this 😊

@hassec hassec closed this as completed Jun 11, 2021
@hassec hassec added the wontfix label Jun 11, 2021
@hassec hassec removed this from the v1.00 milestone Jun 11, 2021
@tenzap
Copy link
Author

tenzap commented Jun 11, 2021

I'm not sure I understand everything very well.

I understand that you claim that the metadata has been modified by another tool which didn't update the IFD correctly resulting in exiv2 not being able to understand them. Again I don't know what happened to these test files (the provider of the files didn't answer to my email unfortunately). If input is bad, I can understand that exiv2 may not want to fix them like exiftool does.

I believe canon_hdr_NO.jpg and canon_hdr_YES.jpg are two different pictures, they are not related in sense of one being a derivative of the other in terms of exif metadata.

Concerning composite, it is not that I want it particularly, it was just to show all the differences I get when making a diff, I didn't mean in anyway that it is a bug in exiv2. I event didn't know Composite was actually a "computed" tag by exiftool.

My report was mainly to show that it seems some tags are lost in the process of deleting a thumbnail (and probably any other operation on the exif metadata), I don't have the knowledge to understand/dig more.

Thanks for having had a look at all this

@clanmills
Copy link
Collaborator

When I went for a walk today, I started to thing about this bug and thought I'll investigate using -dt on an image from my Canon IXUS 185 Point and Shoot". I'm pleased to say that:

  1. The layout of the metadata in my canon image is very similar to Canon PowerShot SX60 HS in your test images.
  2. The behaviour of -dt on my image looks correct.
  3. There is no collateral metadata damage inflicted by -dt

Your test images:

$ exiv2 -g make/i -g model/i canon*.jpg
canon_hdr_NO.jpg      Exif.Image.Make                              Ascii       6  Canon
canon_hdr_NO.jpg      Exif.Image.Model                             Ascii      24  Canon PowerShot SX60 HS
canon_hdr_NO.jpg      Exif.Photo.MakerNote                         Undefined 5414  31 0 1 0 3 0 ...
canon_hdr_NO.jpg      Exif.MakerNote.Offset                        Long        1  786
canon_hdr_NO.jpg      Exif.MakerNote.ByteOrder                     Ascii       3  II
canon_hdr_NO.jpg      Exif.Canon.ModelID                           Long        1  PowerShot SX60 HS
canon_hdr_YES.jpg     Exif.Image.Make                              Ascii       6  Canon
canon_hdr_YES.jpg     Exif.Image.Model                             Ascii      24  Canon PowerShot SX60 HS
canon_hdr_YES.jpg     Exif.Photo.MakerNote                         Undefined 5414  31 0 1 0 3 0 ...
canon_hdr_YES.jpg     Exif.MakerNote.Offset                        Long        1  786
canon_hdr_YES.jpg     Exif.MakerNote.ByteOrder                     Ascii       3  II
canon_hdr_YES.jpg     Exif.Canon.ModelID                           Long        1  PowerShot SX60 HS

My photo:

$ exiv2 -g make/i -g model/i img_2129.jpg
Exif.Image.Make                              Ascii       6  Canon
Exif.Image.Model                             Ascii      16  Canon IXUS 185 
Exif.Photo.MakerNote                         Undefined 5870  31 0 1 0 3 0 ...
Exif.MakerNote.Offset                        Long        1  790
Exif.MakerNote.ByteOrder                     Ascii       3  II
Exif.Canon.ModelID                           Long        1  PowerShot ELPH 185 / IXUS 185 / IXY 200

Extract the metadata, delete the thumbnail and extract again:

$ exiv2 -pa img_2129.jpg > orig.txt
$ exiv2 -dt img_2129.jpg
$ exiv2 -pa img_2129.jpg > dt.txt

Display the changes in the metadata:

$ diff orig.txt dt.txt
27c27
< Exif.Photo.MakerNote                         Undefined 5870  31 0 1 0 3 0 ...
---
> Exif.Photo.MakerNote                         Undefined 5862  31 0 1 0 3 0 ...
112c112
< Exif.Photo.InteroperabilityTag               Long        1  6924
---
> Exif.Photo.InteroperabilityTag               Long        1  6940
128c128
< Exif.Image.GPSTag                            Long        1  7034
---
> Exif.Image.GPSTag                            Long        1  6994
130,135d129
< Exif.Thumbnail.Compression                   Short       1  JPEG (old-style)
< Exif.Thumbnail.XResolution                   Rational    1  180
< Exif.Thumbnail.YResolution                   Rational    1  180
< Exif.Thumbnail.ResolutionUnit                Short       1  inch
< Exif.Thumbnail.JPEGInterchangeFormat         Long        1  20468
< Exif.Thumbnail.JPEGInterchangeFormatLength   Long        1  5248

For sure there is no collateral damage the metadata. The primary difference is of course the removal of the Exif.Thumbnail.* tags. There minor changes to the MakerNote, InteroperabilityTag and surprisingly GPSTag. I could dig in with the debugger and explain the changes byte-by-byte, however I don't believe that's necessary.

I have a feeling that you are relaying this issue from elsewhere. Somebody has said "There's something wrong with the metadata in canon_hdr_YES.jpg or canon_hdr_NO.jpg" The relationship between the two files isn't explained. I encourage you to invite the person who raised this issue to read this analysis provide more information.

I've discussed this on the Exiv2 Chatserver with @hassec. We agree that making progress with this issue isn't possible because it has not been presented with sufficient clarity. Of course, that doesn't mean that Exiv2 is innocent.

I've now retired from Exiv2. If you have additional information about this matter, please update the issue. I am willing to help debug/analyse this issue when more evidence is available.

@tenzap
Copy link
Author

tenzap commented Jun 12, 2021

These files are provided by this repo.

I used them to test my code in this app which uses exiv2 to add thumbnails. I noticed the differences I filed in this bug report and found that the issue was not in my code but linked to exiv2 and narrowed it down to show there is some issue somewhere when deleting a thumbnail (inserting also leads to the same diff, but the deletion command was easier to provide a test case rather than inserting it or changing any tag)

I created an issue in the repo to get more info on these files (if they have been transformed or if they are original). My understanding is these are 2 different shots with the same camera, one with HDR enabled, and one with HDR disabled. As you say, it would be much better if we had the original picture if this one is indeed transformed. Hopefully we will have an update on this to be sure where the problem actually lies.

BTW, there are other canon files in that repo for which there is no problem. Only these two picture show that bug.

@tenzap
Copy link
Author

tenzap commented Jun 12, 2021

I tried with two pictures I found on the internet and which are said to be original.
They are taken by the same camera (Canon PowerShot SX60 HS) as those from the initial report:

Removal of thumbnails by exiv2 showed nothing wrong.

This tends to confirm that canon_hdr_YES.jpg & canon_hdr_NO.jpg are not the original & what @hassec said:

Apparently there are multiple things that can cause this... One of which is editing a file with software that doesn't properly handle these makernotes.

I asked again the original contributor of the canon_hdr_YES.jpg & canon_hdr_NO.jpg if by chance he could provide the original pictures. Let's see.

@clanmills clanmills reopened this Jun 12, 2021
@clanmills
Copy link
Collaborator

Thank for following through on this. I'll self-assign and reopen the issue. Let's not use the word bug until we have a solid case that exiv2 is behaving incorrectly.

@clanmills clanmills self-assigned this Jun 12, 2021
@clanmills clanmills added this to the v1.00 milestone Jun 12, 2021
@clanmills
Copy link
Collaborator

I'm also assigning this to milestone v1.00. In the release notes, I list issues which are "Withdrawn/No Action".

@clanmills
Copy link
Collaborator

@tenzap I'm impressed to see you have an application to add thumbnail to images. That capability has never been implemented in Exiv2. Could you think about joining Team Exiv2 and porting your code into the library. I've retired from Exiv2, so I'm not offering to mentor or support you. However I've retired after 13 years of working on the code in the knowledge that there is group of friendly, clever engineers contributing to Exiv2 and I know you'll enjoy working with them.

@tenzap
Copy link
Author

tenzap commented Jun 13, 2021

It is possible to add thumbnails with exiv2 with -it option, I simply reused what is already in exiv2.

Thank you for your proposal, but sorry I don't plan to join the team, I'm more sort of a hobby developer.

Thanks for the great exiv2 tool/lib

@tenzap
Copy link
Author

tenzap commented Jun 13, 2021

I just added some code to add the mandatory exif tags in case there is no exif metadata at all in the file.

You may find it here

@clanmills clanmills modified the milestones: v1.00, v0.27.4 Jun 15, 2021
@clanmills
Copy link
Collaborator

I'm making up the release notes for v0.27.4. I'm going to assign this to v0.27.4 and close it. If/when more information concerning this is available, please open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug makerNote Anything related to one of the various supported MakerNote formats wontfix
Projects
None yet
Development

No branches or pull requests

4 participants