File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import (
15
15
"image/color"
16
16
"io"
17
17
"io/ioutil"
18
+ "math"
18
19
19
20
"golang.org/x/image/tiff/lzw"
20
21
)
@@ -72,6 +73,9 @@ func (d *decoder) ifdUint(p []byte) (u []uint, err error) {
72
73
var raw []byte
73
74
datatype := d .byteOrder .Uint16 (p [2 :4 ])
74
75
count := d .byteOrder .Uint32 (p [4 :8 ])
76
+ if count > math .MaxInt32 / lengths [datatype ] {
77
+ return nil , FormatError ("IFD data too large" )
78
+ }
75
79
if datalen := lengths [datatype ] * count ; datalen > 4 {
76
80
// The IFD contains a pointer to the real value.
77
81
raw = make ([]byte , datalen )
Original file line number Diff line number Diff line change @@ -214,6 +214,25 @@ func TestZeroSizedImages(t *testing.T) {
214
214
}
215
215
}
216
216
217
+ // TestLargeIFDEntry verifies that a large IFD entry does not cause Decode
218
+ // to panic.
219
+ // Issue 10596.
220
+ func TestLargeIFDEntry (t * testing.T ) {
221
+ testdata := "II*\x00 \x08 \x00 \x00 \x00 \f \x00 0000000000" +
222
+ "00000000000000000000" +
223
+ "00000000000000000000" +
224
+ "00000000000000000000" +
225
+ "00000000000000\x17 \x01 \x04 \x00 \x01 \x00 " +
226
+ "\x00 \xc0 000000000000000000" +
227
+ "00000000000000000000" +
228
+ "00000000000000000000" +
229
+ "000000"
230
+ _ , err := Decode (strings .NewReader (testdata ))
231
+ if err == nil {
232
+ t .Fatal ("Decode with large IFD entry: got nil error, want non-nil" )
233
+ }
234
+ }
235
+
217
236
// benchmarkDecode benchmarks the decoding of an image.
218
237
func benchmarkDecode (b * testing.B , filename string ) {
219
238
b .StopTimer ()
You can’t perform that action at this time.
0 commit comments