Skip to content

return ErrUnexpectedEOF when Decode input is too short#53

Merged
mvdan merged 1 commit intomasterfrom
unexpected-eof
Sep 6, 2021
Merged

return ErrUnexpectedEOF when Decode input is too short#53
mvdan merged 1 commit intomasterfrom
unexpected-eof

Conversation

@mvdan
Copy link
Contributor

@mvdan mvdan commented Sep 4, 2021

(see commit message)

@welcome

This comment has been minimized.

The added test cases would fail before this fix:

    --- FAIL: TestDecodeError/Empty (0.00s)
        unmarshal_test.go:28: Decode("") got "EOF", want "unexpected EOF"
    --- FAIL: TestDecodeError/NoSpace (0.00s)
        unmarshal_test.go:28: Decode("foo") got "EOF", want "unexpected EOF"

They would still return an error, but they'd just return io.EOF.
While that error signals that we've hit the end of input,
it doesn't signal to the codec user that something went wrong.
An io.EOF is not a worrying error, in many situations.

If the input is empty, or is too short to be a valid git object,
we should return a clear error to signal the operation did not work.
io.ErrUnexpectedEOF is unambiguous,
and will make go-ipfs start erroring on this edge case.

For ipfs/kubo#8378.
@warpfork
Copy link
Member

warpfork commented Sep 6, 2021

EDIT: whoops, commented on wrong PR.

@mvdan mvdan merged commit 0508c26 into master Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants