Commit c2013e8a authored by Nigel Tao's avatar Nigel Tao

image/jpeg: return a FormatError when hitting an unexpected io.EOF

inside Huffman-encoded data.

Fixes #6450.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/69830043
parent a9600502
...@@ -37,6 +37,9 @@ func (d *decoder) ensureNBits(n int) error { ...@@ -37,6 +37,9 @@ func (d *decoder) ensureNBits(n int) error {
for d.b.n < n { for d.b.n < n {
c, err := d.r.ReadByte() c, err := d.r.ReadByte()
if err != nil { if err != nil {
if err == io.EOF {
return FormatError("short Huffman data")
}
return err return err
} }
d.b.a = d.b.a<<8 | uint32(c) d.b.a = d.b.a<<8 | uint32(c)
...@@ -50,6 +53,9 @@ func (d *decoder) ensureNBits(n int) error { ...@@ -50,6 +53,9 @@ func (d *decoder) ensureNBits(n int) error {
if c == 0xff { if c == 0xff {
c, err = d.r.ReadByte() c, err = d.r.ReadByte()
if err != nil { if err != nil {
if err == io.EOF {
return FormatError("short Huffman data")
}
return err return err
} }
if c != 0x00 { if c != 0x00 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment