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

On some file, the value extracted for the field "DateTimeOriginal" is truncated. #134

Open
hsq125 opened this issue Apr 5, 2022 · 1 comment

Comments

@hsq125
Copy link

hsq125 commented Apr 5, 2022

For some image, the following code will truncate the DateTimleOriginal.

import piexif
path='20_BIKE_C_4_002.jpg'
if __name__ == '__main__':
    exif_dict = piexif.load(path)
    ts = exif_dict['Exif'][piexif.ExifIFD.DateTimeOriginal]
    print(ts)

will produce

b'2021:08:06 16:10:4'

instead of

b'2021:08:06 16:10:41'

The test image can be downloaded here https://issue-report-resources.s3.eu-central-1.amazonaws.com/piexif/20_BIKE_C_4_002.jpg

Important to be noted that the date is correctly extracted by other tools such as exiftool on Linux.

ExifTool Version Number         : 11.88
File Name                       : 20_BIKE_C_4_002.jpg
[...]
Date/Time Original              : 2021:08:06 16:10:41
JFIF Version                    : 1.02
[...]

Octave

@Dobatymo
Copy link

Dobatymo commented Jun 11, 2023

@hsq125 I checked this file. According to the spec, DateTimeOriginal is a ascii string which must be \0 terminated and the tag length must include the \0 terminator. In your file the length (19) does not include the \0 terminator thus making it a invalid exif structure. Because of that, piexif cuts of the last character.

Other libraries are smart enough to handle this by reading the full length for the field and simply cutting of \0 bytes if necessary.

I encountered various files like this as well, so maybe piexif could implement this smarter handling as well, even though these files are against the spec.

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