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 <r@golang.org>
if _, err := io.ReadFull(d.r, d.tmp[:6]); err != nil {
return fmt.Errorf("gif: can't read graphic control: %s", err)
}
+ if d.tmp[0] != 4 {
+ return fmt.Errorf("gif: invalid graphic control extension block size: %d", d.tmp[0])
+ }
flags := d.tmp[1]
d.disposalMethod = (flags & gcDisposalMethodMask) >> 2
d.delayTime = int(d.tmp[2]) | int(d.tmp[3])<<8
d.transparentIndex = d.tmp[4]
d.hasTransparentIndex = true
}
+ if d.tmp[5] != 0 {
+ return fmt.Errorf("gif: invalid graphic control extension block terminator: %d", d.tmp[5])
+ }
return nil
}
for transparentIndex := 0; transparentIndex < 3; transparentIndex++ {
if transparentIndex < 2 {
// Write the graphic control for the transparent index.
- b.WriteString("\x21\xf9\x00\x01\x00\x00")
+ b.WriteString("\x21\xf9\x04\x01\x00\x00")
b.WriteByte(byte(transparentIndex))
b.WriteByte(0)
}