Skip to content

Commit ac0ee77

Browse files
committed
image/gif: be stricter on parsing graphic control extensions.
See Section 23. Graphic Control Extension of the spec: https://www.w3.org/Graphics/GIF/spec-gif89a.txt Change-Id: Ie78b4ff4aa97e1b332ade67ae4fa25f7c0770610 Reviewed-on: https://go-review.googlesource.com/22547 Reviewed-by: Rob Pike <[email protected]>
1 parent cb97fd7 commit ac0ee77

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/image/gif/reader.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,19 @@ func (d *decoder) readGraphicControl() error {
349349
if _, err := io.ReadFull(d.r, d.tmp[:6]); err != nil {
350350
return fmt.Errorf("gif: can't read graphic control: %s", err)
351351
}
352+
if d.tmp[0] != 4 {
353+
return fmt.Errorf("gif: invalid graphic control extension block size: %d", d.tmp[0])
354+
}
352355
flags := d.tmp[1]
353356
d.disposalMethod = (flags & gcDisposalMethodMask) >> 2
354357
d.delayTime = int(d.tmp[2]) | int(d.tmp[3])<<8
355358
if flags&gcTransparentColorSet != 0 {
356359
d.transparentIndex = d.tmp[4]
357360
d.hasTransparentIndex = true
358361
}
362+
if d.tmp[5] != 0 {
363+
return fmt.Errorf("gif: invalid graphic control extension block terminator: %d", d.tmp[5])
364+
}
359365
return nil
360366
}
361367

src/image/gif/reader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestTransparentIndex(t *testing.T) {
9797
for transparentIndex := 0; transparentIndex < 3; transparentIndex++ {
9898
if transparentIndex < 2 {
9999
// Write the graphic control for the transparent index.
100-
b.WriteString("\x21\xf9\x00\x01\x00\x00")
100+
b.WriteString("\x21\xf9\x04\x01\x00\x00")
101101
b.WriteByte(byte(transparentIndex))
102102
b.WriteByte(0)
103103
}

0 commit comments

Comments
 (0)