mirror of https://github.com/dsoprea/go-exif.git
ifd_enumerate.go:
- Invalid tag-type sets the tag-ID so that we can include it in the log. - Other logging enhancements. - Removed newline - Incorporate the thumbnail into the furthest-offset counter. - Thumbnail() no longer panics ErrNoThumbnail and just returns it. - This is a managed error, not a true panic condition. - Collect() now builds index with FQ IFD paths, not non-FQ.dustin/add_skipped_tags_tracking
parent
70b6dc8a1a
commit
71e87d5e22
|
@ -229,6 +229,7 @@ func (ie *IfdEnumerate) parseTag(fqIfdPath string, tagPosition int, bp *bytePars
|
||||||
|
|
||||||
if tagType.IsValid() == false {
|
if tagType.IsValid() == false {
|
||||||
ite = &IfdTagEntry{
|
ite = &IfdTagEntry{
|
||||||
|
tagId: tagId,
|
||||||
tagType: tagType,
|
tagType: tagType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,7 +295,10 @@ func (ie *IfdEnumerate) ParseIfd(fqIfdPath string, ifdIndex int, bp *byteParser,
|
||||||
ite, err := ie.parseTag(fqIfdPath, i, bp)
|
ite, err := ie.parseTag(fqIfdPath, i, bp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if log.Is(err, ErrTagTypeNotValid) == true {
|
if log.Is(err, ErrTagTypeNotValid) == true {
|
||||||
ifdEnumerateLogger.Warningf(nil, "Tag in IFD [%s] at position (%d) has invalid type (%d) and will be skipped.", fqIfdPath, i, ite.tagType)
|
// Technically, we have the type on-file in the tags-index, but
|
||||||
|
// if the type stored alongside the data disagrees with it,
|
||||||
|
// which it apparently does, all bets are off.
|
||||||
|
ifdEnumerateLogger.Warningf(nil, "Tag (0x%04x) in IFD [%s] at position (%d) has invalid type (%d) and will be skipped.", ite.tagId, fqIfdPath, i, ite.tagType)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,10 +345,12 @@ func (ie *IfdEnumerate) ParseIfd(fqIfdPath string, ifdIndex int, bp *byteParser,
|
||||||
// [likely] not even in the standard list of known tags.
|
// [likely] not even in the standard list of known tags.
|
||||||
if ite.ChildIfdPath() != "" {
|
if ite.ChildIfdPath() != "" {
|
||||||
if doDescend == true {
|
if doDescend == true {
|
||||||
ifdEnumerateLogger.Debugf(nil, "Descending to IFD [%s].", ite.ChildIfdPath())
|
ifdEnumerateLogger.Debugf(nil, "Descending from IFD [%s] to IFD [%s].", fqIfdPath, ite.ChildIfdPath())
|
||||||
|
|
||||||
err := ie.scan(ite.ChildFqIfdPath(), ite.getValueOffset(), visitor)
|
err := ie.scan(ite.ChildFqIfdPath(), ite.getValueOffset(), visitor)
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
|
ifdEnumerateLogger.Debugf(nil, "Ascending from IFD [%s] to IFD [%s].", ite.ChildIfdPath(), fqIfdPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,6 +360,20 @@ func (ie *IfdEnumerate) ParseIfd(fqIfdPath string, ifdIndex int, bp *byteParser,
|
||||||
if enumeratorThumbnailOffset != nil && enumeratorThumbnailSize != nil {
|
if enumeratorThumbnailOffset != nil && enumeratorThumbnailSize != nil {
|
||||||
thumbnailData, err = ie.parseThumbnail(enumeratorThumbnailOffset, enumeratorThumbnailSize)
|
thumbnailData, err = ie.parseThumbnail(enumeratorThumbnailOffset, enumeratorThumbnailSize)
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
|
// In this case, the value is always an offset.
|
||||||
|
offset := enumeratorThumbnailOffset.getValueOffset()
|
||||||
|
|
||||||
|
// This this case, the value is always a length.
|
||||||
|
length := enumeratorThumbnailSize.getValueOffset()
|
||||||
|
|
||||||
|
ifdEnumerateLogger.Debugf(nil, "Found thumbnail in IFD [%s]. Its offset is (%d) and is (%d) bytes.", fqIfdPath, offset, length)
|
||||||
|
|
||||||
|
furthestOffset := offset + length
|
||||||
|
|
||||||
|
if furthestOffset > ie.furthestOffset {
|
||||||
|
ie.furthestOffset = furthestOffset
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nextIfdOffset, _, err = bp.getUint32()
|
nextIfdOffset, _, err = bp.getUint32()
|
||||||
|
@ -575,14 +595,9 @@ func (ifd *Ifd) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ifd *Ifd) Thumbnail() (data []byte, err error) {
|
func (ifd *Ifd) Thumbnail() (data []byte, err error) {
|
||||||
defer func() {
|
|
||||||
if state := recover(); state != nil {
|
|
||||||
err = log.Wrap(state.(error))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if ifd.thumbnailData == nil {
|
if ifd.thumbnailData == nil {
|
||||||
log.Panic(ErrNoThumbnail)
|
return nil, ErrNoThumbnail
|
||||||
}
|
}
|
||||||
|
|
||||||
return ifd.thumbnailData, nil
|
return ifd.thumbnailData, nil
|
||||||
|
@ -1108,13 +1123,12 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32) (index IfdIndex, err error
|
||||||
|
|
||||||
// Install into by-name buckets.
|
// Install into by-name buckets.
|
||||||
|
|
||||||
if list_, found := lookup[ifdPath]; found == true {
|
if list_, found := lookup[fqIfdPath]; found == true {
|
||||||
lookup[ifdPath] = append(list_, ifd)
|
lookup[fqIfdPath] = append(list_, ifd)
|
||||||
} else {
|
} else {
|
||||||
list_ = make([]*Ifd, 1)
|
lookup[fqIfdPath] = []*Ifd{
|
||||||
list_[0] = ifd
|
ifd,
|
||||||
|
}
|
||||||
lookup[ifdPath] = list_
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a link from the previous IFD in the chain to us.
|
// Add a link from the previous IFD in the chain to us.
|
||||||
|
@ -1225,7 +1239,10 @@ func (ie *IfdEnumerate) FurthestOffset() uint32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseOneIfd is a hack to use an IE to parse a raw IFD block. Can be used for
|
// ParseOneIfd is a hack to use an IE to parse a raw IFD block. Can be used for
|
||||||
// testing.
|
// testing. The fqIfdPath ("fully-qualified IFD path") will be less qualified
|
||||||
|
// in that the numeric index will always be zero (the zeroth child) rather than
|
||||||
|
// the proper number (if its actually a sibling to the first child, for
|
||||||
|
// instance).
|
||||||
func ParseOneIfd(ifdMapping *IfdMapping, tagIndex *TagIndex, fqIfdPath, ifdPath string, byteOrder binary.ByteOrder, ifdBlock []byte, visitor TagVisitorFn) (nextIfdOffset uint32, entries []*IfdTagEntry, err error) {
|
func ParseOneIfd(ifdMapping *IfdMapping, tagIndex *TagIndex, fqIfdPath, ifdPath string, byteOrder binary.ByteOrder, ifdBlock []byte, visitor TagVisitorFn) (nextIfdOffset uint32, entries []*IfdTagEntry, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if state := recover(); state != nil {
|
if state := recover(); state != nil {
|
||||||
|
@ -1329,7 +1346,7 @@ func FindIfdFromRootIfd(rootIfd *Ifd, ifdPath string) (ifd *Ifd, err error) {
|
||||||
// If we didn't find the sibling, add it.
|
// If we didn't find the sibling, add it.
|
||||||
for i = 0; i < itii.Index; i++ {
|
for i = 0; i < itii.Index; i++ {
|
||||||
if thisIfd.NextIfd == nil {
|
if thisIfd.NextIfd == nil {
|
||||||
log.Panicf("IFD [%s] does not have (%d) occurrences/siblings\n", thisIfd.IfdPath, itii.Index)
|
log.Panicf("IFD [%s] does not have (%d) occurrences/siblings", thisIfd.IfdPath, itii.Index)
|
||||||
}
|
}
|
||||||
|
|
||||||
thisIfd = thisIfd.NextIfd
|
thisIfd = thisIfd.NextIfd
|
||||||
|
|
Loading…
Reference in New Issue