Collect goes into an infinite loop for a broken jpg file

pull/56/head
Paul van Santen 2021-03-29 17:49:35 +02:00
parent d154f10435
commit 827ecdad3d
No known key found for this signature in database
GPG Key ID: AD10F40CB69516B6
3 changed files with 33 additions and 3 deletions

BIN
v3/assets/broken_exif.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

View File

@ -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)

View File

@ -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
}