goexif icon indicating copy to clipboard operation
goexif copied to clipboard

ExifIFDPointer decode failed when attempting to read EXIF data.

Open FooSoft opened this issue 5 years ago • 4 comments

Attempting to extract GPS metadata from an image known to contain it causes the following error to be logged:

loading EXIF sub-IFD: exif: sub-IFD ExifIFDPointer decode failed: zero length tag value

Go version:

go version go1.12.6 linux/amd64

Test code (basically copy-paste of sample):

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/rwcarlsen/goexif/exif"
	"github.com/rwcarlsen/goexif/mknote"
)

func main() {
	fname := "osaka.jpg"

	f, err := os.Open(fname)
	if err != nil {
		log.Fatal(err)
	}

	// Optionally register camera makenote data parsing - currently Nikon and
	// Canon are supported.
	exif.RegisterParsers(mknote.All...)

	x, err := exif.Decode(f)
	if err != nil {
		log.Fatal(err)
	}

	camModel, _ := x.Get(exif.Model) // normally, don't ignore errors!
	fmt.Println(camModel.StringVal())

	focal, _ := x.Get(exif.FocalLength)
	numer, denom, _ := focal.Rat2(0) // retrieve first (only) rat. value
	fmt.Printf("%v/%v", numer, denom)

	// Two convenience functions exist for date/time taken and GPS coords:
	tm, _ := x.DateTime()
	fmt.Println("Taken: ", tm)

	lat, long, _ := x.LatLong()
	fmt.Println("lat, long: ", lat, ", ", long)
}

Image file: https://github.com/FooSoft/goldsmith-components/raw/master/plugins/exif/testdata/source/osaka.jpg

FooSoft avatar Jul 06 '19 03:07 FooSoft

I should add that this was taken on a Huawei Mate SE, and all pictures it saves have this problem.

FooSoft avatar Jul 06 '19 05:07 FooSoft

Same here with pictures of a Huawei P20. Here is the output of a sample picture created with ExifTool: https://pastebin.com/bWF8Nus5

mrauh avatar Aug 17 '19 12:08 mrauh

I was able to solve my problem by ignoring non-critical decoding errors and using DateTime() instead of Get(exif.DateTimeOriginal).

@FooSoft As you are trying to extract GPS metadata, maybe the LatLong() function works for you.

Here is my snippet that finally works:

x, err := exif.Decode(f)
if err != nil {
	if exif.IsCriticalError(err) {
		return nil, err
	}
}
defer f.Close()

dt, err := x.DateTime()
if err != nil {
	return nil, err
}

// Use dt...

mrauh avatar Aug 17 '19 14:08 mrauh

@mrauh thanks for the example, I did not realize IsCriticalError was something that I should be looking for; does not appear to be very intuitive.

FooSoft avatar Aug 17 '19 23:08 FooSoft