Skip to content

image/jpeg: unreadByteStuffedByte call cannot be fulfilled #10387

Closed
@dvyukov

Description

@dvyukov

Run the following program on the following input:

package main

import (
    "bytes"
    "image/jpeg"
    "io/ioutil"
    "os"
)

func main() {
    data, _ := ioutil.ReadFile(os.Args[1])
    img, err := jpeg.Decode(bytes.NewReader(data))
    if err != nil {
        return
    }
    var w bytes.Buffer
    err = jpeg.Encode(&w, img, nil)
    if err != nil {
        panic(err)
    }
}

https://drive.google.com/file/d/0B20Uwp8Hs1oCU2NTRmdxNmRBb0E/view?usp=sharing

It crashes with:

panic: jpeg: unreadByteStuffedByte call cannot be fulfilled

goroutine 1 [running]:
runtime.gopanic(0x49ac60, 0xc20800e570)
    src/runtime/panic.go:477 +0x3fe fp=0xc208041a08 sp=0xc208041988
image/jpeg.(*decoder).unreadByteStuffedByte(0xc20806e000)
    src/image/jpeg/reader.go:173 +0x8a fp=0xc208041a48 sp=0xc208041a08
image/jpeg.(*decoder).decodeHuffman(0xc20806e000, 0xc20806f150, 0xd, 0x0, 0x0)
    src/image/jpeg/huffman.go:190 +0x1cb fp=0xc208041ae8 sp=0xc208041a48
image/jpeg.(*decoder).processSOS(0xc20806e000, 0x6, 0x0, 0x0)
    src/image/jpeg/scan.go:232 +0x17e5 fp=0xc208041de8 sp=0xc208041ae8
image/jpeg.(*decoder).decode(0xc20806e000, 0x7fe5025251c0, 0xc208014450, 0x574300, 0x0, 0x0, 0x0, 0x0)
    src/image/jpeg/reader.go:619 +0xa4e fp=0xc208041e88 sp=0xc208041de8
image/jpeg.Decode(0x7fe5025251c0, 0xc208014450, 0x0, 0x0, 0x0, 0x0)
    src/image/jpeg/reader.go:762 +0x69 fp=0xc208041ed0 sp=0xc208041e88
main.main()
    jpeg.go:12 +0x132 fp=0xc208041f90 sp=0xc208041ed0

My repository is on commit 8ac129e.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions