Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/image/riff: (*Reader) Next() drops io.ReadFull error #16236

Closed
richardlehane opened this issue Jul 1, 2016 · 1 comment
Closed

x/image/riff: (*Reader) Next() drops io.ReadFull error #16236

richardlehane opened this issue Jul 1, 2016 · 1 comment
Assignees
Milestone

Comments

@richardlehane
Copy link

@richardlehane richardlehane commented Jul 1, 2016

I'm getting panics and memory issues using golang.org/x/image/riff package with malformed riff files.

E.g. https://play.golang.org/p/cCN1VQ4Dz2

These seem to be due to an IO error being dropped in the (*Reader) Next() method.

From line 132 in https://github.com/golang/image/blob/master/riff/riff.go:

    if _, err = io.ReadFull(z.r, z.buf[:chunkHeaderSize]); err != nil {
        if z.err == io.EOF || z.err == io.ErrUnexpectedEOF {
            z.err = errShortChunkHeader
        }
        return FourCC{}, 0, nil, z.err
    }
    chunkID = FourCC{z.buf[0], z.buf[1], z.buf[2], z.buf[3]}
    z.chunkLen = u32(z.buf[4:])
    z.padded = z.chunkLen&1 == 1
    z.chunkReader = &chunkReader{z}
    return chunkID, z.chunkLen, z.chunkReader, nil

The err var in the first line of that snippet is a named return value but it is never used/ returned by the method.

Can fix by assigning the io.ReadFull error to z.err instead:

    if _, z.err = io.ReadFull(z.r, z.buf[:chunkHeaderSize]); z.err != nil {
        if z.err == io.EOF || z.err == io.ErrUnexpectedEOF {
            z.err = errShortChunkHeader
        }
        return FourCC{}, 0, nil, z.err
    }
    chunkID = FourCC{z.buf[0], z.buf[1], z.buf[2], z.buf[3]}
    z.chunkLen = u32(z.buf[4:])
    z.padded = z.chunkLen&1 == 1
    z.chunkReader = &chunkReader{z}
    return chunkID, z.chunkLen, z.chunkReader, nil

as at golang/image@ 8550bb5

@bradfitz bradfitz changed the title image/riff: (*Reader) Next() drops io.ReadFull error x/image/riff: (*Reader) Next() drops io.ReadFull error Jul 1, 2016
@bradfitz bradfitz added this to the Unreleased milestone Jul 1, 2016
@gopherbot
Copy link

@gopherbot gopherbot commented Jul 1, 2016

CL https://golang.org/cl/24638 mentions this issue.

@golang golang locked and limited conversation to collaborators Jul 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.