Reported byte swapping in GetConsoleScreenBufferInfoEx #21334

Closed
opened 2026-01-31 07:41:27 +00:00 by claunia · 11 comments
Owner

Originally created by @DHowett on GitHub (Mar 1, 2024).

This is the first we've heard of GCSBIEx returning invalid data in the color palette! Do you have a test app that exhibits this? It sounds (sorry, based on "... detect that the API is malfunctioning") like it isn't consistent.

(EDIT: Oh, I see you added one. Thanks!)

An app running in a ConPTY based terminal experiences R/B swapping in GCSBIEx/SCSBIEx, in addition to a canned "default palette" instead of the real palette.

An app running in a legacy ConHost based terminal experiences correct R/B values, and receives the real palette.

So, an app has to use detection heuristics to figure out whether GCSBIEx is malfunctioning.

Originally posted by @chrisant996 in https://github.com/microsoft/terminal/issues/10639#issuecomment-1973871217

Originally created by @DHowett on GitHub (Mar 1, 2024). > This is the first we've heard of GCSBIEx returning invalid data in the color palette! Do you have a test app that exhibits this? It sounds (sorry, based on "... _detect_ that the API is malfunctioning") like it isn't consistent. > > (EDIT: Oh, I see you added one. Thanks!) An app running in a ConPTY based terminal experiences R/B swapping in GCSBIEx/SCSBIEx, in addition to a canned "default palette" instead of the real palette. An app running in a legacy ConHost based terminal experiences correct R/B values, and receives the real palette. So, an app has to use detection heuristics to figure out whether GCSBIEx is malfunctioning. _Originally posted by @chrisant996 in https://github.com/microsoft/terminal/issues/10639#issuecomment-1973871217_
Author
Owner

@chrisant996 commented on GitHub (Mar 1, 2024):

Here's the sample app that demonstrates the issue:

repro_colortable.zip

I repro the R/B byte swapping in WT 18, 19, and 20 (at least as of 1.20.240124001-llm).

@chrisant996 commented on GitHub (Mar 1, 2024): Here's the sample app that demonstrates the issue: [repro_colortable.zip](https://github.com/microsoft/terminal/files/14465693/repro_colortable.zip) I repro the R/B byte swapping in WT 18, 19, and 20 (at least as of 1.20.240124001-llm).
Author
Owner

@DHowett commented on GitHub (Mar 1, 2024):

I'm having trouble reproducing this. Terminal via conpty on the left, conhost on the right.

image

VSCode (also uses ConPTY -- critically, it uses a different version than the one in Terminal)

image

@DHowett commented on GitHub (Mar 1, 2024): I'm having trouble reproducing this. Terminal via conpty on the left, conhost on the right. ![image](https://github.com/microsoft/terminal/assets/189190/6aab7c2c-55c4-4115-9769-4892c17e5160) VSCode (also uses ConPTY -- critically, it uses a _different version_ than the one in Terminal) ![image](https://github.com/microsoft/terminal/assets/189190/504833d3-30e2-4312-8b3f-ed9d54c30b44)
Author
Owner

@chrisant996 commented on GitHub (Mar 1, 2024):

@DHowett hm. I will take another look and reply back with findings.

@chrisant996 commented on GitHub (Mar 1, 2024): @DHowett hm. I will take another look and reply back with findings.
Author
Owner

@chrisant996 commented on GitHub (Mar 1, 2024):

Also note the scrolling issue that this app exposes -- that's also pretty mysterious, and it seems to permanently infect the terminal window until it's closed.

I.e. if you run the app in a terminal where it ends up scrolling at the bottom of the terminal window.

@chrisant996 commented on GitHub (Mar 1, 2024): Also note the scrolling issue that this app exposes -- that's also pretty mysterious, and it seems to permanently infect the terminal window until it's closed. I.e. if you run the app in a terminal where it ends up scrolling at the bottom of the terminal window.
Author
Owner

@DHowett commented on GitHub (Mar 1, 2024):

Also note the scrolling issue that this app exposes -- that's also pretty mysterious, and it seems to permanently infect the terminal window until it's closed.

Unfortunately, yeah. This one is very much "known" and "probably wrecked until we get some notion of app compat" (since we can't fix it without breaking everyone who already accommodated it)

https://github.com/microsoft/terminal/issues/3698#issuecomment-558734017 and #3698 in general, which we should rename to "[these APIs] use an inconsistent coordinate system"

@DHowett commented on GitHub (Mar 1, 2024): > Also note the scrolling issue that this app exposes -- that's also pretty mysterious, and it seems to permanently infect the terminal window until it's closed. Unfortunately, yeah. This one is very much "known" and "probably wrecked until we get some notion of app compat" (since we can't fix it without breaking everyone who already accommodated it) https://github.com/microsoft/terminal/issues/3698#issuecomment-558734017 and #3698 in general, which we should rename to "[these APIs] use an inconsistent coordinate system"
Author
Owner

@DHowett commented on GitHub (Mar 1, 2024):

Oh, but fortunately I was able to get out of it by just resizing the window once (or un-maximizing and re-maximizing it)

@DHowett commented on GitHub (Mar 1, 2024): Oh, but fortunately I was able to get out of it by just resizing the window once (or un-maximizing and re-maximizing it)
Author
Owner

@chrisant996 commented on GitHub (Mar 1, 2024):

Unfortunately, yeah. This one is very much "known" and "probably wrecked until we get some notion of app compat" (since we can't fix it without breaking everyone who already accommodated it)

#3698 (comment) and #3698 in general, which we should rename to "[these APIs] use an inconsistent coordinate system"

Ah, got it, thanks. This is apparently the first time I've used SCSBI [or -Ex] in any app (I just now grep'd all the console apps I've ever written, which is not a small number 😅). I never knew about that quirk in SCSBI -- thanks for the heads-up! 😁

@chrisant996 commented on GitHub (Mar 1, 2024): > Unfortunately, yeah. This one is very much "known" and "probably wrecked until we get some notion of app compat" (since we can't fix it without breaking everyone who already accommodated it) > > [#3698 (comment)](https://github.com/microsoft/terminal/issues/3698#issuecomment-558734017) and #3698 in general, which we should rename to "[these APIs] use an inconsistent coordinate system" Ah, got it, thanks. This is apparently the first time I've used SCSBI [or -Ex] in any app (I just now grep'd all the console apps I've ever written, which is not a small number 😅). I never knew about that quirk in SCSBI -- thanks for the heads-up! 😁
Author
Owner

@chrisant996 commented on GitHub (Mar 1, 2024):

I'm having trouble reproducing this. Terminal via conpty on the left, conhost on the right.

Agreed. I can't repro either. 🤔

For now, I'll chalk it up to maybe having accidentally used ANSI indices instead of VGA indices. I had made the observation weeks ago in the context of something else, and I put together the app to test my observation, but I never had time to follow up and post until now -- and by now I've lost all memory and context about the situation at the time. I'll assume I just goofed on the observation and was too distracted to notice. 🤷‍♂️

Thanks for trying it!

@chrisant996 commented on GitHub (Mar 1, 2024): > I'm having trouble reproducing this. Terminal via conpty on the left, conhost on the right. Agreed. I can't repro either. 🤔 For now, I'll chalk it up to maybe having accidentally used ANSI indices instead of VGA indices. I had made the observation weeks ago in the context of something else, and I put together the app to test my observation, but I never had time to follow up and post until now -- and by now I've lost all memory and context about the situation at the time. I'll assume I just goofed on the observation and was too distracted to notice. 🤷‍♂️ Thanks for trying it!
Author
Owner

@chrisant996 commented on GitHub (Mar 1, 2024):

Please close this as Not Planned and PEBKAC, if there's a suitable Label 😅

@chrisant996 commented on GitHub (Mar 1, 2024): Please close this as Not Planned and PEBKAC, if there's a suitable Label 😅
Author
Owner

@DHowett commented on GitHub (Mar 1, 2024):

Hey, it happens to all of us! Please please please do file issues if you run into stuff like this - we can't afford to miss one. That's worth the occasional misfire... and the team knows I've been on the producing end of not-a-bug bug reports too 😁

@DHowett commented on GitHub (Mar 1, 2024): Hey, it happens to all of us! Please please please do file issues if you run into stuff like this - we can't afford to miss one. That's worth the occasional misfire... and the team knows I've been on the producing end of not-a-bug bug reports too :grin:
Author
Owner

@chrisant996 commented on GitHub (Mar 1, 2024):

For closure:

Ah, yup -- I found the context.

It was indeed due to a missing conversion from ANSI 0..7 order to VGA 0..7 order for colors. And the only colors being used happened to be Red and Blue. Whose positions in the 0..7 order are swapped.

And thus while in a hurry I forgot about the ANSI/VGA conversion, and observed that Red and Blue bytes were swapped. Which was an accurate observation at the lowest level, but quite inaccurate in the bigger picture.

@chrisant996 commented on GitHub (Mar 1, 2024): ### For closure: Ah, yup -- I found the context. It was indeed due to a missing conversion from ANSI 0..7 order to VGA 0..7 order for colors. And the only colors being used happened to be Red and Blue. Whose positions in the 0..7 order are swapped. And thus while in a hurry I forgot about the ANSI/VGA conversion, and observed that Red and Blue bytes were swapped. Which was an accurate observation at the lowest level, but quite inaccurate in the bigger picture.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#21334