Skip to content

image/jpeg: index out of range #10388

Closed
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/0B20Uwp8Hs1oCSnFPQTIxU0FyR1E/view?usp=sharing

It crashes with:

panic: runtime error: index out of range

goroutine 1 [running]:
runtime.gopanic(0x4b2ac0, 0xc20800e210)
    src/runtime/panic.go:477 +0x3fe fp=0xc208041ac0 sp=0xc208041a40
runtime.panicindex()
    src/runtime/panic.go:12 +0x52 fp=0xc208041ae8 sp=0xc208041ac0
image/jpeg.(*decoder).processSOS(0xc208070000, 0xa, 0x0, 0x0)
    src/image/jpeg/scan.go:218 +0x1ca3 fp=0xc208041de8 sp=0xc208041ae8
image/jpeg.(*decoder).decode(0xc208070000, 0x7f7d0183b1c0, 0xc208014450, 0x574300, 0x0, 0x0, 0x0, 0x0)
    src/image/jpeg/reader.go:619 +0xa4e fp=0xc208041e88 sp=0xc208041de8
image/jpeg.Decode(0x7f7d0183b1c0, 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