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

ReadConsoleOutputAttribute returns zeros in the attribute buffer #8745

Closed
Maximus5 opened this issue Jan 12, 2021 · 7 comments
Closed

ReadConsoleOutputAttribute returns zeros in the attribute buffer #8745

Maximus5 opened this issue Jan 12, 2021 · 7 comments
Labels
Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Area-VT Virtual Terminal sequence support Needs-Attention The core contributors need to come back around and look at this ASAP. Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Product-Conhost For issues in the Console codebase

Comments

@Maximus5
Copy link

Environment

Windows build number: 10.0.18363.1256
ConEmu: 210111

Steps to reproduce

  1. Run it as: conemu64.exe -basic -run cmd.exe /k wsl.exe
  2. WSL prompt appears, type exit
  3. cmd.exe prompt appears, but the first 4 characters are invisible. The reason is that ReadConsoleOutputAttribute returns malformed data (all zeros in attributes array).

Expected behavior

ReadConsoleOutputAttribute returns 7-s in the attributes array.

Actual behavior

ReadConsoleOutputAttribute returns 0-s in the attributes array.

Details

Sample code used in ConEmu to read attribute data

#define ROWID_USED_CELLS 4
WORD  nAttrs[ROWID_USED_CELLS];
const COORD crLeft = {0, nRow};
DWORD nRead = 0;
if (!ReadConsoleOutputAttribute(hConOut, nAttrs, ROWID_USED_CELLS, crLeft, &nRead) || (nRead != ROWID_USED_CELLS))
   return false;

So, on exit from wsl.exe back to cmd.exe prompt (we started it as cmd /k wsl.exe), ReadConsoleOutputAttribute returns TRUE, nRead is equal to 4, but nAttrs is {0,0,0,0}.

For now, I found the workaround - ReadConsoleOutputW works properly, it returns cell attribute 7.

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jan 12, 2021
@vefatica
Copy link

I think you'll be interested in #5940.

@zadjii-msft
Copy link
Member

Hmm. That's a good point that we saw something like this in #5940. It does seem weird to me though. That other issue dealt with a improper conversion of 256/RGB attributes to legacy ones, while in this case, there's presumably no such conversion happening.

@Maximus5 can you quick share a screenshot of what those four characters look like? I think it's extremely bizarre that it's only those 4 that are returning bad data, and not the rest of the prompt.

@zadjii-msft zadjii-msft added Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Area-VT Virtual Terminal sequence support Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something Product-Conhost For issues in the Console codebase labels Jan 12, 2021
@Maximus5
Copy link
Author

@zadjii-msft Sorry if I described unclearly. The problem is not with only first 4 characters. I mentioned this magic number only because ConEmu utilizes first four cells to overwrite some attributes for internal purposes. So, I've noted that attributes are zeros, because ConEmu explicitly writes new attributes, e.g. hi_byte_flags | lo_byte_from_conhost.

2021-01-12-12-35-44

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Jan 12, 2021
@j4james
Copy link
Collaborator

j4james commented Jan 12, 2021

I think this issue has been fixed. If it wasn't #6358, it may have been #6698, or a combination of the two (possibly one of the other PRs from around that time). I'm too lazy to dig through the changes, but I vaguely remember something about the buffer being initialized with different attributes in different circumstances. Sometimes it would be white-on-black, but sometimes it would use the VT default colors (which I suspect ReadConsoleOutputAttribute may not have read back correctly).

I think at this point we always initialize with the VT default colors, but all the legacy console APIs are now able to read that back correctly (i.e. returning 0x07, which is what legacy apps would expect).

I can reproduce the problem using the cmd.exe that's included in Windows 10.0.18363.1256, but it works correctly if I try the same thing with the latest version of OpenConsole, so I'm assuming that means it's fixed.

@j4james
Copy link
Collaborator

j4james commented Jan 12, 2021

Just to be clear, I'm not testing in ConEmu, but I wrote a little test app that calls ReadConsoleOutputAttribute to query the initial attribute values. When run from cmd.exe /k wsl.exe I get 0x00, and when run from OpenConsole.exe cmd.exe /k wsl.exe I get 0x07.

@DHowett
Copy link
Member

DHowett commented Feb 17, 2021

So, I've gone to try to reproduce this. I'm running 19041/19042, and I can't. I suspect you released a fix in ConEmu? 😄

Regardless -- James' hunch appears to be correct. It's been fixed in newer versions, even though we can't quite pinpoint exactly where. When we added 256- and 24-bit-color support and some of the VT work that exposed "default" versus "legacy" colors, we likely broke something in a subtle way that ConEmu tripped over.

I'm going to close this one out. If you see any other cases where you're storing stuff in attributes and they're getting corrupted, or we're not storing something quite right, please let me know.

@DHowett DHowett closed this as completed Feb 17, 2021
@Maximus5
Copy link
Author

@DHowett Yes, the latest ConEmu version where this may be observable is 210111.
https://github.com/Maximus5/ConEmu/releases/tag/v21.01.11

If it's fixed, than everything is ok. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Area-VT Virtual Terminal sequence support Needs-Attention The core contributors need to come back around and look at this ASAP. Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Product-Conhost For issues in the Console codebase
Projects
None yet
Development

No branches or pull requests

5 participants