PowerShell / PowerShell/Win32-OpenSSH

Faking pixel dimensions in the `TIOCGWINSZ` struct causes scaling issues for Sixel apps

Open
#2,349 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Investigate
Dominant language
No language data
Stars
8.3k
Forks
819
PR merge metrics
No merged PRs in 30d

Description

Prerequisites
  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.
Steps to reproduce

Applications that produce Sixel images will often want to scale them to fit a certain area of the display, measured in terms of character cells, i.e. columns and rows. For example, you can use the timg utility to scale an image to fit within 20 columns with a command like this:

timg -f sixel -g 20x snake.png

In order for this to work, the application needs to know the pixel dimensions of a character cell so they can calculate the equivalent pixel size that the image should be scaled to. On Linux, this is often determined by looking at the winsize struct returned by TIOCGWINSZ, dividing the ws_xpixel field by the ws_col field, and the ws_ypixel field by the ws_row field.

However, that doesn't work when connecting with Win32-OpenSSH, because the those fields are hardcoded with fake dimensions (640x480). See here:

https://github.com/PowerShell/openssh-portable/blob/efa17c848b3e579d8a4a0e71edf6d233b5e30917/contrib/win32/win32compat/misc.c#L500-L501

It would be preferable if you simply filled the ws_xpixel and ws_ypixel fields with zero, because applications will typically then fallback to using an escape sequence to query the cell size.

Expected behavior
The rendered image from the example above should occupy exactly 20 columns.
Actual behavior
Depending on the size of the terminal window (in terms of rows and columns), the image can end up much bigger or smaller than expected.
Error details

Environment data
Name                           Value
----                           -----
PSVersion                      7.2.23
PSEdition                      Core
GitCommitId                    7.2.23
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Version

v9.8.2.0p2-Preview

Visuals

This is what the test case above looks like when run directly from within a WSL bash shell (note that it occupies exactly 20 columns):

Working test case scaled to 20 columns

This is what it looks like when connected to the same system with Win32-OpenSSH (it's incorrectly scaled to 8 columns):

Failing test case scaled to 8 columns

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the scaling behavior with timg over Win32-OpenSSH and compare it with the WSL result. Inspect contrib/win32/win32compat/misc.c around the winsize fields referenced in the issue. Done means Sixel applications receive dimensions that allow the escape-sequence fallback and the example occupies exactly 20 columns.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
cli, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.