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

Improve EXIF UserComment handling #27

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {
}
base := "../testdata"

if err := filepath.Walk(base, func(path string, info os.FileInfo, err error) error {
if err := filepath.Walk(filepath.Join(base, "images"), func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
Expand Down
20 changes: 0 additions & 20 deletions gen/testdata_exiftool/fuzz/FuzzDecodeJPG/11b4836f396ea129.json

This file was deleted.

20 changes: 0 additions & 20 deletions gen/testdata_exiftool/fuzz/FuzzDecodeJPG/1ccacf70a7af5b48.json

This file was deleted.

20 changes: 0 additions & 20 deletions gen/testdata_exiftool/fuzz/FuzzDecodeJPG/9c46786602e37dac.json

This file was deleted.

20 changes: 0 additions & 20 deletions gen/testdata_exiftool/fuzz/FuzzDecodeJPG/be5ae98210f88f5a.json

This file was deleted.

20 changes: 0 additions & 20 deletions gen/testdata_exiftool/fuzz/FuzzDecodeJPG/c6c20bc8145eb1ca.json

This file was deleted.

19 changes: 0 additions & 19 deletions gen/testdata_exiftool/fuzz/FuzzDecodePNG/1d4b3e6d8e083b46.json

This file was deleted.

19 changes: 0 additions & 19 deletions gen/testdata_exiftool/fuzz/FuzzDecodePNG/c99a254e79433054.json

This file was deleted.

19 changes: 0 additions & 19 deletions gen/testdata_exiftool/fuzz/FuzzDecodePNG/cd66d0b7410fd5c5.json

This file was deleted.

19 changes: 0 additions & 19 deletions gen/testdata_exiftool/fuzz/FuzzDecodePNG/e24f658a5bbdb019.json

This file was deleted.

20 changes: 0 additions & 20 deletions gen/testdata_exiftool/fuzz/FuzzDecodeWebP/cd8c6f6742f1c6a7.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[{
"SourceFile": "../testdata/images/huge_tag_exif.jpg",
"SourceFile": "../testdata/images/corrupt/huge_tag_exif.jpg",
"ExifTool": {
"ExifToolVersion": 12.76,
"Warning": "JPEG format error"
},
"File": {
"FileName": "huge_tag_exif.jpg",
"Directory": "../testdata/images",
"Directory": "../testdata/images/corrupt",
"FileSize": 65536,
"FilePermissions": 100644,
"FileType": "JPEG",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[{
"SourceFile": "../testdata/images/infinite_loop_exif.jpg",
"SourceFile": "../testdata/images/corrupt/infinite_loop_exif.jpg",
"ExifTool": {
"ExifToolVersion": 12.76,
"Warning": "Suspicious IFD0 offset for XResolution"
},
"File": {
"FileName": "infinite_loop_exif.jpg",
"Directory": "../testdata/images",
"Directory": "../testdata/images/corrupt",
"FileSize": 3738,
"FilePermissions": 100644,
"FileType": "JPEG",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[{
"SourceFile": "../testdata/images/max_uint32_exif.jpg",
"SourceFile": "../testdata/images/corrupt/max_uint32_exif.jpg",
"ExifTool": {
"ExifToolVersion": 12.76,
"Warning": "JPEG format error"
},
"File": {
"FileName": "max_uint32_exif.jpg",
"Directory": "../testdata/images",
"Directory": "../testdata/images/corrupt",
"FileSize": 65536,
"FilePermissions": 100644,
"FileType": "JPEG",
Expand Down
87 changes: 87 additions & 0 deletions gen/testdata_exiftool/images/hugo-issue-12669.jpg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[{
"SourceFile": "../testdata/images/hugo-issue-12669.jpg",
"ExifTool": {
"ExifToolVersion": 12.76
},
"File": {
"FileName": "hugo-issue-12669.jpg",
"Directory": "../testdata/images",
"FileSize": 5772106,
"FilePermissions": 100644,
"FileType": "JPEG",
"FileTypeExtension": "JPG",
"MIMEType": "image/jpeg",
"ExifByteOrder": "II",
"ImageWidth": 4032,
"ImageHeight": 2268,
"EncodingProcess": 0,
"BitsPerSample": 8,
"ColorComponents": 3,
"YCbCrSubSampling": "2 2"
},
"EXIF": {
"ImageWidth": 4032,
"ImageHeight": 2268,
"Make": "samsung",
"Model": "SM-G950U",
"Orientation": 1,
"XResolution": 72,
"YResolution": 72,
"ResolutionUnit": 2,
"Software": "G950USQS8DTJ1",
"ModifyDate": "2021:01:17 11:34:47",
"YCbCrPositioning": 1,
"ExposureTime": 0.0003172588832,
"FNumber": 1.7,
"ExposureProgram": 2,
"ISO": 50,
"ExifVersion": "0220",
"DateTimeOriginal": "2021:01:17 11:34:47",
"CreateDate": "2021:01:17 11:34:47",
"ComponentsConfiguration": "1 2 3 0",
"ShutterSpeedValue": "0.000317270278919785",
"ApertureValue": 1.6993699982773,
"BrightnessValue": 8.98,
"ExposureCompensation": 0,
"MaxApertureValue": 1.6993699982773,
"MeteringMode": 2,
"LightSource": 0,
"Flash": 0,
"FocalLength": 4.25,
"UserComment": "\n",
"FlashpixVersion": "0100",
"ColorSpace": 1,
"ExifImageWidth": 4032,
"ExifImageHeight": 2268,
"InteropIndex": "R98",
"InteropVersion": "0100",
"SensingMethod": 2,
"SceneType": 1,
"ExposureMode": 0,
"WhiteBalance": 0,
"FocalLengthIn35mmFormat": 26,
"SceneCaptureType": 0,
"ImageUniqueID": "F12QSJA00SM F12QSKB01SB",
"GPSVersionID": "2 2 0 0",
"GPSLatitudeRef": "N",
"GPSLatitude": 0,
"GPSLongitudeRef": "E",
"GPSLongitude": 0,
"GPSAltitudeRef": 0,
"GPSAltitude": 0,
"GPSTimeStamp": "18:34:47",
"GPSDateStamp": "2021:01:17",
"Compression": 6,
"ThumbnailOffset": 6312,
"ThumbnailLength": 16863
},
"MakerNotes": {
"MakerNoteVersion": "0100",
"DeviceType": 73728,
"RawDataByteOrder": 0,
"RawDataCFAPattern": 1,
"FaceDetect": 0,
"TimeStamp": "2021:01:17 19:34:47.374+01:00",
"MCCData": 310
}
}]
34 changes: 34 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,31 @@ func (vc) convertStringToInt(ctx valueConverterContext, v any) any {
return i
}

func (c vc) convertUserComment(ctx valueConverterContext, v any) any {
// UserComment tag is identified based on an ID code in a fixed 8-byte area at the start of the tag data area.
b, ok := typeAssert[[]byte](ctx, v)
if !ok {
return ""
}
if len(b) < 8 {
return ""
}
id := string(b[:8])

switch id {
case "ASCII\x00\x00\x00":
s := printableString(string(trimBytesNulls(b[8:])))
if !isASCII(s) {
return ""
}
return s
case "UNICODE\x00":
return printableString(string(trimBytesNulls(b[8:])))
default:
return ""
}
}

func (vc) ratNum(v any) any {
switch vv := v.(type) {
case Rat[uint32]:
Expand Down Expand Up @@ -357,6 +382,15 @@ func (c vc) toDegrees(v any) (float64, error) {
}
}

func isASCII(s string) bool {
for i := 0; i < len(s); i++ {
if s[i] > unicode.MaxASCII {
return false
}
}
return true
}

func printableString(s string) string {
ss := strings.Map(func(r rune) rune {
if unicode.IsGraphic(r) {
Expand Down
Loading
Loading