-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
os: readConsole corrupts multibyte characters on Windows #17939
Comments
CL https://golang.org/cl/31114 mentions this issue. |
This doesn't seem like a bug to me; Read is not guaranteed to read all the available bytes. I'll mark it as a possible fix for the future since it would help with optimization, but you should always remember that Read is free to not fill the buffer whenever it wants. |
But it should call ReadFile with enough bytes because ReadFile break half of multi-byte unread. When the leading byte is read, trailing byte(s) never be read. This is clearly with C code. So this should be fixed until next release. |
The second example looks bug to me and it is reproducible.
Note that 'あ' = [e3 81 82], '\r' = [0d], '\n' = [0a].
Also here are results in go1.7.3:
So this is a regression. 1af769d Even worse, my input was swallowed when:
|
Indeed, that looks like a bug to me. Apologies for misinterpreting the report before; I thought it was only that reads were being broken up into multiple calls. If we're dropping bytes, that's very bad and could be a release blocker. Thanks for the sample output. |
@hirochachacha please add your example to TestReadStdin in os package to see what is wrong, and report here. Thank you. Alex |
@hirochachacha please add your example to TestReadStdin in os package, to see what is going on, and report here. Thank you. Alex |
@alexbrainman I tried, but it's not reproducible there.
then,
Note that 'あ' = [82 a0] in CP932 encoding. Current code uses I don't know https://msdn.microsoft.com/en-us/library/windows/desktop/aa365467(v=vs.85).aspx |
Yes. It looks weird. We ask for 1 byte, but ReadFile says that it returned returned 2 bytes. I wonder if ReadFile actually have written correct bytes into the buffer (actually second byte past the end of our buffer). Also, please, tell us if ReadFile returns error. Change your code to:
and tell us what it prints. Thank you. Alex |
Here you are.
Unfortunately, readFile doesn't return error even if truncation occurred. |
Thank you. I will think about this. Alex |
CL https://golang.org/cl/33451 mentions this issue. |
What version of Go are you using (
go version
)?go version devel +5af7553 Wed Nov 9 00:21:04 2016 +0000 windows/amd64
What operating system and processor architecture are you using (
go env
)?Windows 7 64bit
What did you do?
#17427 (comment)
go run
and typehello\n
on the prompt>
.What did you expect to see?
output
[7 "hello\r\n" <nil>]
What did you see instead?
When 100 bytes buffer is given, readConsole should be filled with
hello\r\n
on console. Because GetConsoleMode() is ENABLE_LINE_INPUT and if call ReadFile with enough buffer, it fill ashello\r\n
.https://go-review.googlesource.com/#/c/31114/ will fix this.
The text was updated successfully, but these errors were encountered: