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

io: Copy reports ErrShortWrite for long writes #39978

Closed
jnjackins opened this issue Jul 1, 2020 · 3 comments
Closed

io: Copy reports ErrShortWrite for long writes #39978

jnjackins opened this issue Jul 1, 2020 · 3 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@jnjackins
Copy link
Contributor

jnjackins commented Jul 1, 2020

What version of Go are you using (go version)?

$ go version
go version devel +c875503cf7 Sun Jun 28 03:14:10 2020 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOOS="darwin"
GOPROXY="https://proxy.golang.org,direct"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

I implemented a buggy io.Writer which sometimes writes too many bytes (i.e., more that the length of the []byte parameter to the Write method), and used io.Copy to write to it.

https://play.golang.org/p/UeO1GCEvmNP

What did you expect to see?

A reasonable error message (indicating that the wrong number of bytes were written, or too many bytes were written)

What did you see instead?

ErrShortWrite.

Based on the documented meaning of this error variable, I believe io.Copy is using it incorrectly in this case.

ErrShortWrite means that a write accepted fewer bytes than requested but failed to return an explicit error.

For what it's worth, this came up while debugging real code: the Writer in question buffers writes and was buggy.

@ianlancetaylor
Copy link
Contributor

For the record, bufio.Scanner recently started returning bufio.ErrBadReadCount for a similar case, which displays as bufio.Scanner: Read returned impossible count.

@ianlancetaylor ianlancetaylor added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Jul 1, 2020
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Jul 1, 2020
@gopherbot
Copy link

Change https://golang.org/cl/240740 mentions this issue: io: add ErrBadWriteCount

@gopherbot
Copy link

Change https://golang.org/cl/262877 mentions this issue: io: unexport ErrBadWriteCount

gopherbot pushed a commit that referenced this issue Oct 16, 2020
It was added in CL 240740 to fix #39978
but without any discussion of the exported API.

The error can still be returned to fix the issue,
without adding new public API to package io.

Also fix the error message to refer to lower-case write
like the other errors in the package.

Change-Id: I134de5eaf3ac903d73913c5cadcde904c5255d79
Reviewed-on: https://go-review.googlesource.com/c/go/+/262877
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Oct 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants