File tree Expand file tree Collapse file tree 6 files changed +49
-3
lines changed
gen/testdata_exiftool/images Expand file tree Collapse file tree 6 files changed +49
-3
lines changed Original file line number Diff line number Diff line change 1+ [{
2+ "SourceFile" : " ../testdata/images/largeexif.png" ,
3+ "ExifTool" : {
4+ "ExifToolVersion" : 12.76 ,
5+ "Warning" : " Processing TIFF-like data after unknown 16-byte header"
6+ },
7+ "File" : {
8+ "FileName" : " largeexif.png" ,
9+ "Directory" : " ../testdata/images" ,
10+ "FileSize" : 1310710 ,
11+ "FilePermissions" : 100644 ,
12+ "ExifByteOrder" : " MM"
13+ }
14+ }]
Original file line number Diff line number Diff line change @@ -113,6 +113,28 @@ func Decode(opts Options) (err error) {
113113 }
114114 }
115115
116+ const (
117+ defaultLimitNumTags = 5000
118+ defaultLimitTagSize = 10000
119+ )
120+
121+ if opts .LimitNumTags == 0 {
122+ opts .LimitNumTags = defaultLimitNumTags
123+ }
124+ if opts .LimitTagSize == 0 {
125+ opts .LimitTagSize = defaultLimitTagSize
126+ }
127+
128+ var tagCount uint32
129+ shouldHandleTag := opts .ShouldHandleTag
130+ opts .ShouldHandleTag = func (ti TagInfo ) bool {
131+ tagCount ++
132+ if tagCount > opts .LimitNumTags {
133+ panic (ErrStopWalking )
134+ }
135+ return shouldHandleTag (ti )
136+ }
137+
116138 if opts .HandleTag == nil {
117139 opts .HandleTag = func (TagInfo ) error { return nil }
118140 }
@@ -246,6 +268,16 @@ type Options struct {
246268 // Mostly useful for testing.
247269 // If set to 0, the decoder will not time out.
248270 Timeout time.Duration
271+
272+ // LimitNumTags is the maximum number of tags to read.
273+ // Default value is 5000.
274+ LimitNumTags uint32
275+
276+ // LimitTagSize is the maximum size in bytes of a tag value to read.
277+ // Tag values larger than this will be skipped without notice.
278+ // Note that this limit is not relevant for the XMP source.
279+ // Default value is 10000.
280+ LimitTagSize uint32
249281}
250282
251283// TagInfo contains information about a tag.
Original file line number Diff line number Diff line change 88 "errors"
99 "fmt"
1010 "io"
11+ "maps"
1112 "math"
1213 "math/rand"
1314 "os"
@@ -23,7 +24,6 @@ import (
2324
2425 qt "github.com/frankban/quicktest"
2526 "github.com/google/go-cmp/cmp"
26- "maps"
2727)
2828
2929func TestDecodeAllImageFormats (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -383,7 +383,7 @@ func (e *metaDecoderEXIF) decodeTag(namespace string) error {
383383 }
384384
385385 // Below is EXIF
386- if ! e .opts .Sources .Has (EXIF ) {
386+ if ! e .opts .Sources .Has (EXIF ) || valLen > e . opts . LimitTagSize {
387387 e .skip (4 )
388388 return nil
389389 }
Original file line number Diff line number Diff line change @@ -273,7 +273,7 @@ func (e *metaDecoderIPTC) decodeRecord(stringSlices map[TagInfo][]string) error
273273 Namespace : recordDef .RecordName ,
274274 }
275275
276- if ! e .opts .ShouldHandleTag (ti ) {
276+ if recordSize > uint16 ( e . opts . LimitTagSize ) || ! e .opts .ShouldHandleTag (ti ) {
277277 e .skip (int64 (recordSize ))
278278 return nil
279279 }
You can’t perform that action at this time.
0 commit comments