mirror of
https://github.com/dsoprea/go-exif.git
synced 2025-05-31 11:41:57 +00:00
utility.go: Skip unknown tags in GetFlatExifData
This makes its behavior consistent with other iteration/enumeration functions and also mitigates handling errors by unsuspecting callers.
This commit is contained in:
parent
232d5acc36
commit
d2495e29dd
@ -13,6 +13,10 @@ import (
|
|||||||
"github.com/dsoprea/go-exif/v2/undefined"
|
"github.com/dsoprea/go-exif/v2/undefined"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
utilityLogger = log.NewLogger("exif.utility")
|
||||||
|
)
|
||||||
|
|
||||||
// ParseExifFullTimestamp parses dates like "2018:11:30 13:01:49" into a UTC
|
// ParseExifFullTimestamp parses dates like "2018:11:30 13:01:49" into a UTC
|
||||||
// `time.Time` struct.
|
// `time.Time` struct.
|
||||||
func ParseExifFullTimestamp(fullTimestampPhrase string) (timestamp time.Time, err error) {
|
func ParseExifFullTimestamp(fullTimestampPhrase string) (timestamp time.Time, err error) {
|
||||||
@ -118,14 +122,28 @@ func GetFlatExifData(exifData []byte) (exifTags []ExifTag, err error) {
|
|||||||
|
|
||||||
ti := NewTagIndex()
|
ti := NewTagIndex()
|
||||||
for _, ite := range ifd.Entries {
|
for _, ite := range ifd.Entries {
|
||||||
|
tagId := ite.TagId()
|
||||||
|
tagType := ite.TagType()
|
||||||
|
|
||||||
tagName := ""
|
tagName := ""
|
||||||
|
|
||||||
it, err := ti.Get(ifd.IfdPath, ite.TagId())
|
it, err := ti.Get(ifd.IfdPath, ite.tagId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If it's a non-standard tag, just leave the name blank.
|
|
||||||
if log.Is(err, ErrTagNotFound) != true {
|
if log.Is(err, ErrTagNotFound) != true {
|
||||||
log.PanicIf(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is an unknown tag.
|
||||||
|
|
||||||
|
// This is supposed to be a convenience function and if we were
|
||||||
|
// to keep the name empty or set it to some placeholder, it
|
||||||
|
// might be mismanaged by the package that is calling us. If
|
||||||
|
// they want to specifically manage these types of tags, they
|
||||||
|
// can use more advanced functionality to specifically -handle
|
||||||
|
// unknown tags.
|
||||||
|
utilityLogger.Warningf(nil, "Tag with ID (0x%04x) in IFD [%s] is not recognized and will be ignored.", tagId, ifd.FqIfdPath)
|
||||||
|
|
||||||
|
continue
|
||||||
} else {
|
} else {
|
||||||
tagName = it.Name
|
tagName = it.Name
|
||||||
}
|
}
|
||||||
@ -148,11 +166,9 @@ func GetFlatExifData(exifData []byte) (exifTags []ExifTag, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tagType := ite.TagType()
|
|
||||||
|
|
||||||
et := ExifTag{
|
et := ExifTag{
|
||||||
IfdPath: ifd.FqIfdPath,
|
IfdPath: ifd.FqIfdPath,
|
||||||
TagId: ite.TagId(),
|
TagId: tagId,
|
||||||
TagName: tagName,
|
TagName: tagName,
|
||||||
TagTypeId: tagType,
|
TagTypeId: tagType,
|
||||||
TagTypeName: tagType.String(),
|
TagTypeName: tagType.String(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user