pixiv / go-libjpeg

An implementation of Go binding for libjpeg (or libjpeg-turbo).
BSD 3-Clause "New" or "Revised" License
156 stars 52 forks source link

Encoding after decoding failed: unsupported image type #55

Closed bayandin closed 5 years ago

bayandin commented 5 years ago

Here is another issue I found with the help of go-fuzz: I'm able to decode data but aren't able to encode it back.

package main

import (
    "bytes"
    "fmt"

    "github.com/pixiv/go-libjpeg/jpeg"
)

func main() {
    data := []byte("\xff\xd8\xff\xdb\x00C\x000000000000000" +
        "00000000000000000000" +
        "00000000000000000000" +
        "00000000000\xff\xc0\x00\x11\b\x00000" +
        "\x03R\"\x00G\x11\x00B\x11\x00\xff\xda\x00\f\x03R\x00G\x00B" +
        "\x00")

    img, err := jpeg.Decode(bytes.NewReader(data), &jpeg.DecoderOptions{})
    if err != nil {
        return
    }

    var w bytes.Buffer
    err = jpeg.Encode(&w, img, &jpeg.EncoderOptions{})
    if err != nil {
        panic(err)
    }
}

It prints

Invalid SOS parameters for sequential JPEG
panic: unsupported image type

I use go version go1.12.9 darwin/amd64, libjpeg-turbo 2.0.2

harukasan commented 5 years ago

:+1: I fixed in #57.