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

fmt: cannot read more than 254 characters in Windows when calling Fscanln #42551

Open
jimen0 opened this issue Nov 12, 2020 · 1 comment
Open

fmt: cannot read more than 254 characters in Windows when calling Fscanln #42551

jimen0 opened this issue Nov 12, 2020 · 1 comment

Comments

@jimen0
Copy link

@jimen0 jimen0 commented Nov 12, 2020

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

$ go version
go version go1.15.4 darwin/amd64
$ gotip version
go version devel +b34b0aaf69 Thu Nov 12 15:28:43 2020 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Yes. It also reproduces with current tip go version devel +b34b0aaf69 Thu Nov 12 15:28:43 2020 +0000 darwin/amd64

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

go env Output
$ go env
N/A

What did you do?

package main

import (
	"fmt"
	"os"
)

func main() {
	var s string
	_, err := fmt.Fscanln(os.Stdin, &s)
	if err != nil {
		panic(err)
	}

	fmt.Println(s)
}
$ GOOS=windows go build -o reproducer_stdin.exe main.go
$ GOOS=windows gotip build -o reproducer_stdin_tip.exe main.go

What did you expect to see?

On the Windows host, I type A character 257 times after running the program, then press enter key. The Go program reads them correctly.

PS C:\Users\mig\Downloads> .\reproducer_stdin_tip.exe | Measure-Object -char | Select-Object -expand Characters
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
257
PS C:\Users\mig\Downloads> .\reproducer_stdin.exe | Measure-Object -char | Select-Object -expand Characters
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
257

What did you see instead?

On the Windows host, I typed A character 257 times after running the program, then presed enter key. The Go program stdin froze after 254 characters.

PS C:\Users\mig\Downloads> .\reproducer_stdin_tip.exe | Measure-Object -char | Select-Object -expand Characters
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
254
PS C:\Users\mig\Downloads> .\reproducer_stdin.exe | Measure-Object -char | Select-Object -expand Characters
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
254

NOTE: this seems to also be borken when copying&pasting text.

Note: this was tested using a Windows (Windows Server 2012 R2 Datacenter) Azure machine with default settings and environment. Just downloaded the cross-compiled binaries into it and ran them.
Edit: This is also reproducible using Windows Command Prompt using an Azure Windows (Windows 10 Pro) default machine.


I don't really know if this is related to Go at all or an issue with Powershell itself, but I thought it was worth submitting an issue. This was initially discovered by @karelorigin.

Best regards,
Miguel

@jimen0 jimen0 changed the title fmt/Fscanln: cannot read more than 254 characters in Windows Powershell fmt/Fscanln: cannot read more than 254 characters in Windows Nov 12, 2020
@cagedmantis cagedmantis changed the title fmt/Fscanln: cannot read more than 254 characters in Windows fmt: cannot read more than 254 characters in Windows when calling Fscanln Nov 13, 2020
@cagedmantis cagedmantis added this to the Backlog milestone Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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