diff --git a/v3/assets/broken_exif.jpg b/v3/assets/broken_exif.jpg new file mode 100644 index 0000000..682bd04 Binary files /dev/null and b/v3/assets/broken_exif.jpg differ diff --git a/v3/exif_test.go b/v3/exif_test.go index 7737378..2e06387 100644 --- a/v3/exif_test.go +++ b/v3/exif_test.go @@ -2,15 +2,14 @@ package exif import ( "bytes" + "encoding/binary" "fmt" + "io/ioutil" "os" "reflect" "sort" "testing" - "encoding/binary" - "io/ioutil" - "github.com/dsoprea/go-logging" "github.com/dsoprea/go-exif/v3/common" @@ -409,6 +408,31 @@ func TestExif_BuildAndParseExifHeader(t *testing.T) { } } +func TestExif_ParseBrokenExif(t *testing.T) { + file, err := os.Open(getTestBrokenExifFilepath()) + if err != nil { + t.Error(err) + return + } + rawExif, err := SearchAndExtractExifWithReader(file) + if err != nil { + t.Error(err) + return + } + + ifd, err := exifcommon.NewIfdMappingWithStandard() + if err != nil { + t.Error(err) + return + } + tag := NewTagIndex() + _, _, err = Collect(ifd, tag, rawExif) + if err != nil { + t.Error(err) + return + } +} + func ExampleBuildExifHeader() { headerBytes, err := BuildExifHeader(exifcommon.TestDefaultByteOrder, 0x11223344) log.PanicIf(err) diff --git a/v3/testing_common.go b/v3/testing_common.go index 0612764..0247f09 100644 --- a/v3/testing_common.go +++ b/v3/testing_common.go @@ -186,3 +186,9 @@ func getTestGeotiffFilepath() string { testGeotiffFilepath := path.Join(assetsPath, "geotiff_example.tif") return testGeotiffFilepath } + +func getTestBrokenExifFilepath() string { + assetsPath := exifcommon.GetTestAssetsPath() + testBrokenExifFilepath := path.Join(assetsPath, "broken_exif.jpg") + return testBrokenExifFilepath +}