fix: guard TIOCGWINSZ before winpty_set_size to avoid assert on non-tty stdin - #212
Open
davidcoleman007 wants to merge 1 commit into
Open
fix: guard TIOCGWINSZ before winpty_set_size to avoid assert on non-tty stdin#212davidcoleman007 wants to merge 1 commit into
davidcoleman007 wants to merge 1 commit into
Conversation
…ty stdin When stdin is not a tty (e.g. piped from a parent process), ioctl(TIOCGWINSZ) fails and leaves the winsize struct uninitialised. The subsequent memcmp fires spuriously and winpty_set_size(wp, 0, 0) hits the assertion at libwinpty/winpty.cc:924. Fix: only call winpty_set_size when ioctl succeeds and cols/rows are > 0. Apply the same guard to the initial-size path for symmetry.
Author
|
@rprichard thanks for the work on this package! I don't know if this is actively developed these days, but i have been having the above issue consistently when using claude in git bash and windows git sdk. I patched it, tested with both sdk and git bash. Please let me know if there is some additional process to certify this fix? |
Owner
|
Sorry, I haven't been maintaining this project since 2017 or so.
Software that uses winpty ought to switch to using the official Windows
ConPTY API instead, but ConPTY wasn't added until (some version of) Windows
10.
…On Thu, May 21, 2026 at 1:53 PM Dave Coleman ***@***.***> wrote:
*davidcoleman007* left a comment (rprichard/winpty#212)
<#212 (comment)>
@rprichard <https://github.com/rprichard> thanks for the work on this
package!
I don't know if this is actively developed these days, but i have been
having the above issue consistently when using claude in git bash and
windows git sdk. I patched it, tested with both sdk and git bash.
Please let me know if there is some additional process to certify this fix?
—
Reply to this email directly, view it on GitHub
<#212 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAL7753TLDCHJCBF7J5AJ7D435GCZAVCNFSM6AAAAACZHALPMCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DKMJRG44TIMBRG4>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Author
That's a real shame. Interestingly the current git bash distribution shipped by git/Microsoft today is actively including this package, and NOT ConPTY. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When the unix-adapter is invoked with stdin that is not a tty (e.g. piped from a parent process such as an editor's terminal harness, a CI runner, or any non-interactive tool that wraps bash),
ioctl(STDIN_FILENO, TIOCGWINSZ, ...)fails withENOTTY. Both call sites insrc/unix-adapter/main.ccignored the return value, leaving the localwinsizevariable uninitialised. In the resize loop, the subsequentmemcmpagainst the prior size fires spuriously andwinpty_set_size(wp, sz.ws_col, sz.ws_row, NULL)ends up being called withcols == 0 && rows == 0, which trips the assertion in libwinpty:This causes a stream of assertion banners on stderr from any wrapper that pipes bash through winpty without a real console.
Fix
Guard both
ioctl(TIOCGWINSZ)call sites: only act on the result when the call succeeds andws_col/ws_roware positive. The libwinpty invariant inwinpty_set_sizeis correct as-is — the bug was in the caller passing zero dimensions.winpty_set_sizecall entirely if the ioctl failed or reported a degenerate size.Test plan
winpty cmd.exe /c echo hello,winpty --version) still works in mintty.