google-code-export / camlistore

Automatically exported from code.google.com/p/camlistore
Apache License 2.0
0 stars 0 forks source link

djpeg fails with (large?) buffer as stdin #550

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

with the attached image, this works fine:

func boatpic(pic string) error {
    f, err := os.Open(pic)
    if err != nil {
        return err
    }
    defer f.Close()
    cmd := exec.Command("/usr/bin/djpeg", "-scale", "1/2")
    cmd.Stdin = f
    cmd.Stdout = ioutil.Discard
    return cmd.Run()
}

whereas this (which is pretty much what we use in fastjpeg.go) fails:

func boatpic2(pic string) error {
    f, err := os.Open(pic)
    if err != nil {
        return err
    }
    defer f.Close()
    var buf bytes.Buffer
    tr := io.TeeReader(f, &buf)
    var dest bytes.Buffer
    _, err = io.CopyN(&dest, tr, 100)
    if err != nil {
        return err
    }
    mr := io.MultiReader(&buf, f)
    cmd := exec.Command("/usr/bin/djpeg", "-scale", "1/2")
//  cmd := exec.Command("/usr/bin/djpeg", "-memsrc", "-scale", "1/2")
    cmd.Stdin = mr
    cmd.Stdout = ioutil.Discard
    return cmd.Run()
}

Turns out using -memsrc fixes that failure.
It'd be interesting to know why exactly, and/or to report upstream.

Original issue reported on code.google.com by mathieu....@gmail.com on 22 Nov 2014 at 12:52

Attachments:

GoogleCodeExporter commented 9 years ago
https://camlistore-review.googlesource.com/4156

Original comment by mathieu....@gmail.com on 22 Nov 2014 at 12:54

GoogleCodeExporter commented 9 years ago
Also I haven't tested if/how -memsrc affects performance. Bill, any clue?

Original comment by mathieu....@gmail.com on 22 Nov 2014 at 12:57

GoogleCodeExporter commented 9 years ago
TODO(mpl): file bug upstream

Original comment by mathieu....@gmail.com on 26 Nov 2014 at 12:49

GoogleCodeExporter commented 9 years ago
even simpler repro case (for discussion with upstream):

func boatpic3(pic string) error {
    data, err := ioutil.ReadFile(pic)
    if err != nil {
        return err
    }
    buf := bytes.NewReader(data)
    cmd := exec.Command("/usr/bin/djpeg", "-scale", "1/2")
    cmd.Stdin = buf
    cmd.Stdout = ioutil.Discard
    return cmd.Run()
}

Original comment by mathieu....@gmail.com on 26 Nov 2014 at 6:58

GoogleCodeExporter commented 9 years ago
bug filed upstream: https://sourceforge.net/p/libjpeg-turbo/bugs/80/

Original comment by mathieu....@gmail.com on 26 Nov 2014 at 7:20

GoogleCodeExporter commented 9 years ago
Go bug: http://golang.org/issue/9173

Original comment by bradfitz@golang.org on 26 Nov 2014 at 10:36

GoogleCodeExporter commented 9 years ago
fixed with a work-around as far as Camlistore is concerned
009e63ea77a4a1c1b63ebfe56dd0bfdc4c219c92

Original comment by mathieu....@gmail.com on 2 Dec 2014 at 2:46

GoogleCodeExporter commented 9 years ago
This issue has moved to https://camlistore.org/issue/550

Original comment by bradfitz on 14 Dec 2014 at 11:37