type breaks UTF-8 characters at 512 char boundary #7269

Closed
opened 2026-01-31 00:59:37 +00:00 by claunia · 11 comments
Owner

Originally created by @luke1961 on GitHub (Apr 4, 2020).

Environment

Windows build number: [run `[Environment]::OSVersion` for powershell, or `ver` for cmd]
Windows Terminal version (if applicable):

Any other software?

Steps to reproduce

Expected behavior

Actual behavior

Originally created by @luke1961 on GitHub (Apr 4, 2020). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Windows build number: [run `[Environment]::OSVersion` for powershell, or `ver` for cmd] Windows Terminal version (if applicable): Any other software? ``` # Steps to reproduce <!-- A description of how to trigger this bug. --> # Expected behavior <!-- A description of what you're expecting, possibly containing screenshots or reference material. --> # Actual behavior <!-- What's actually happening? -->
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 4, 2020):

Come on, you didn’t put any info in the bug report.

@DHowett-MSFT commented on GitHub (Apr 4, 2020): Come on, you didn’t put any info in the bug report.
Author
Owner

@luke1961 commented on GitHub (Apr 4, 2020):

Environment:
Win32NT 10.0.18363.0 Microsoft Windows NT 10.0.18363.0
Conhost 10.0.18362.1
Files needed:
bug.txt
This is a UTF-8 encoded file with some escape sequences using popular line drawing characters

Steps to reproduce:

  1. Open Windows Command Prompt (without Legacy mode, of course)
  2. Place file bug.txt (included in this bug report) in the current folder.
  3. Run
    chcp 65001
  4. Run
    type bug.txt
  5. Observe two unexpected characters towards the end of line in addition to UTF-8 frame characters as on the image below
    bug

I know that the two characters with tiny question marks in them are UTF-8 EF BF BD (REPLACEMENT CHARACTER) but they are not included in my file and there is no reason for they appearance on screen because all characters which I try to print are represented in the font Consolas.

I have spent considerable time looking into the problem, double checking the escape sequences but no luck.

I am a great fan of your new Terminal software and I wish you even more success with it.

Please help.

@luke1961 commented on GitHub (Apr 4, 2020): Environment: Win32NT 10.0.18363.0 Microsoft Windows NT 10.0.18363.0 Conhost 10.0.18362.1 Files needed: [bug.txt](https://github.com/microsoft/terminal/files/4430493/bug.txt) This is a UTF-8 encoded file with some escape sequences using popular line drawing characters Steps to reproduce: 1. Open Windows Command Prompt (without Legacy mode, of course) 2. Place file bug.txt (included in this bug report) in the current folder. 3. Run chcp 65001 4. Run type bug.txt 5. Observe two unexpected characters towards the end of line in addition to UTF-8 frame characters as on the image below ![bug](https://user-images.githubusercontent.com/6032592/78414747-9e310b00-75eb-11ea-9b4e-c9a62062d602.jpg) I know that the two characters with tiny question marks in them are UTF-8 EF BF BD (REPLACEMENT CHARACTER) but they are not included in my file and there is no reason for they appearance on screen because all characters which I try to print are represented in the font Consolas. I have spent considerable time looking into the problem, double checking the escape sequences but no luck. I am a great fan of your new Terminal software and I wish you even more success with it. Please help.
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 4, 2020):

Thanks for the info! We will look at this on Monday.

Does it happen if you do the same steps from powershell?

@DHowett-MSFT commented on GitHub (Apr 4, 2020): Thanks for the info! We will look at this on Monday. Does it happen if you do the same steps from powershell?
Author
Owner

@luke1961 commented on GitHub (Apr 4, 2020):

PowerShell even with chcp 65001 will not display the file as utf-8 so no frame characters are going to appear at all. I can duplicate it only in the command prompt. This is a very interesting issue. There is a single '=' in the file included. I mean the real equal, not the horizontal frame characters looking like 'equal' which are before that character. If I remove this one equal character from the file the garbage characters will disappear.

@luke1961 commented on GitHub (Apr 4, 2020): PowerShell even with chcp 65001 will not display the file as utf-8 so no frame characters are going to appear at all. I can duplicate it only in the command prompt. This is a very interesting issue. There is a single '=' in the file included. I mean the real equal, not the horizontal frame characters looking like 'equal' which are before that character. If I remove this one equal character from the file the garbage characters will disappear.
Author
Owner

@luke1961 commented on GitHub (Apr 4, 2020):

You may be curious about the origin of the problem. There is a website for tracking covid-19 with command prompt output, you can access it as in the image

covid-19-bug

You see the frame is broken in one point because of the garbage characters in middle of the line. I just extracted a small part from covid.txt to isolate the problem to a small fragment of that file.

@luke1961 commented on GitHub (Apr 4, 2020): You may be curious about the origin of the problem. There is a website for tracking covid-19 with command prompt output, you can access it as in the image ![covid-19-bug](https://user-images.githubusercontent.com/6032592/78415618-d1c26400-75f0-11ea-92cc-c20a97b34052.jpg) You see the frame is broken in one point because of the garbage characters in middle of the line. I just extracted a small part from covid.txt to isolate the problem to a small fragment of that file.
Author
Owner

@j4james commented on GitHub (Apr 4, 2020):

It looks to me like this could be a bug in the type command. The content gets to us via the WriteConsoleW API, and by that time the utf-8 has already been incorrectly decoded. If you instead try to view the file from a WSL bash shell with the Linux cat command, it actually works perfectly.

It appears that their utf-8 decoder is using a 512 byte buffer, and when a utf-8 sequence is split at the buffer boundary, you end up with an error char on either side of the split. For a simple test case you can just create a file with 511 regular ASCII characters followed by one multibyte Unicode character.

@j4james commented on GitHub (Apr 4, 2020): It looks to me like this could be a bug in the `type` command. The content gets to us via the `WriteConsoleW` API, and by that time the utf-8 has already been incorrectly decoded. If you instead try to view the file from a WSL bash shell with the Linux `cat` command, it actually works perfectly. It appears that their utf-8 decoder is using a 512 byte buffer, and when a utf-8 sequence is split at the buffer boundary, you end up with an error char on either side of the split. For a simple test case you can just create a file with 511 regular ASCII characters followed by one multibyte Unicode character.
Author
Owner

@luke1961 commented on GitHub (Apr 4, 2020):

You are absolutely right. I tried cygwin's cat and everything displayed fine. Too bad 'type' command is broken.

@luke1961 commented on GitHub (Apr 4, 2020): You are absolutely right. I tried cygwin's cat and everything displayed fine. Too bad 'type' command is broken.
Author
Owner

@zadjii-msft commented on GitHub (Apr 6, 2020):

I'll leave this open for the team to discuss during triage, but considering the origin of this bug is in type I'm not totally sure we can fix this 😕

@zadjii-msft commented on GitHub (Apr 6, 2020): I'll leave this open for the team to discuss during triage, but considering the origin of this bug is in `type` I'm not totally sure we can fix this 😕
Author
Owner

@german-one commented on GitHub (Apr 6, 2020):

This is a dup of #386 if you'd ask me. My impression is still that CMD converts the UTF-8 chunks to UTF-16 itself which is the reason why the partial handling we already implemented isn't effective. (Same what @j4james wrote above.) @miniksa promised once to have a look into the internal source of the CMD in order to check this. If this is true, and you didn't want to update the CMD anymore as you guys already explained several times, you could close this and #386 with a Resolution-Won't-Fix.

@german-one commented on GitHub (Apr 6, 2020): This is a dup of #386 if you'd ask me. My impression is still that CMD converts the UTF-8 chunks to UTF-16 itself which is the reason why the partial handling we already implemented isn't effective. (Same what @j4james wrote above.) @miniksa promised once to have a look into the internal source of the CMD in order to check this. If this is true, and you didn't want to update the CMD anymore as you guys already explained several times, you could close this and #386 with a `Resolution-Won't-Fix`.
Author
Owner

@zadjii-msft commented on GitHub (Apr 6, 2020):

Oh jeez, you're right, this is that thread. I'll close this one as a dupe, and make sure to move that (very old) thread into an appropriate milestone, so we at least make sure to give it a resolution one way or another.

/dup #386

@zadjii-msft commented on GitHub (Apr 6, 2020): Oh jeez, you're right, this is that thread. I'll close this one as a dupe, and make sure to move that (very old) thread into an appropriate milestone, so we at least make sure to give it a resolution one way or another. /dup #386
Author
Owner

@ghost commented on GitHub (Apr 6, 2020):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost commented on GitHub (Apr 6, 2020): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#7269