xor-gate/goexif2

Crash when exif.MakerNote is empty in Parse (Nikon) + Code to fix it

vomnes opened this issue · 0 comments

Crash when exif.MakerNote is empty in Parse (Nikon) :

panic: runtime error: slice bounds out of range

goroutine 19 [running]:
github.com/xor-gate/goexif2/mknote.(*nikonV3).Parse(0x1443ec0, 0xc420150ea0, 0x0, 0x0)
	/Users/vomnes/go/src/github.com/xor-gate/goexif2/mknote/mknote.go:58 +0x2b4
github.com/xor-gate/goexif2/exif.Decode(0x12e6920, 0xc4204a4060, 0x2, 0x42, 0x0)
	/Users/vomnes/go/src/github.com/xor-gate/goexif2/exif/exif.go:331 +0x366

Code to fix it:

mknote/mknote.go:58
- } else if bytes.Compare(m.Val[:6], []byte("Nikon\000")) != 0 {
+ } else if len(m.Val) < 6 || bytes.Compare(m.Val[:6], []byte("Nikon\000")) != 0 {