Skip to content

gh-110913: Fix WindowsConsoleIO chunking of UTF-8 text - #111007

Merged
zooba merged 4 commits into
python:mainfrom
sorgloomer:issue-110913-windows-console-utf8-boundary
Oct 20, 2023
Merged

gh-110913: Fix WindowsConsoleIO chunking of UTF-8 text#111007
zooba merged 4 commits into
python:mainfrom
sorgloomer:issue-110913-windows-console-utf8-boundary

Conversation

@sorgloomer

@sorgloomersorgloomer commented Oct 17, 2023

Copy link
Copy Markdown
Contributor

@ghost

ghost commented Oct 17, 2023

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@sorgloomer
sorgloomerforce-pushed the issue-110913-windows-console-utf8-boundary branch from b8a5110 to b66a4e4CompareOctober 17, 2023 23:43
@bedevere-app

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@sorgloomer
sorgloomerforce-pushed the issue-110913-windows-console-utf8-boundary branch from b66a4e4 to 709fb94CompareOctober 17, 2023 23:45
@bedevere-app

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@sorgloomer
sorgloomerforce-pushed the issue-110913-windows-console-utf8-boundary branch from 709fb94 to 2be4b92CompareOctober 17, 2023 23:46
@bedevere-app

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@sorgloomer
sorgloomerforce-pushed the issue-110913-windows-console-utf8-boundary branch from 2be4b92 to 2b0bf5bCompareOctober 18, 2023 00:42
@bedevere-app

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@zoobazooba added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Oct 18, 2023
@zooba

Copy link
Copy Markdown
Member

I think we should have a NEWS entry for this, just to acknowledge that we changed the fix. Something like WindowsConsoleIO now correctly chunks large buffers without splitting up UTF-8 sequences

The change looks fine to me, but I'd like one more ACK before merging in case my head still isn't clear.

@sorgloomer

Copy link
Copy Markdown
ContributorAuthor

Thanks! Added the NEWS entry.

Comment threadModules/_io/winconsoleio.c Outdated
Comment threadMisc/NEWS.d/next/Windows/2023-10-19-21-46-18.gh-issue-110913.CWlPfg.rst Outdated

@serhiy-storchakaserhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it even possible to write tests for this?

@zooba

Copy link
Copy Markdown
Member

Is it even possible to write tests for this?

Not without refactoring the entire thing (e.g. to make the actual WriteConsoleW call encoding-unaware and create a specific TextIOWrapper just for this case that does the chunking). Or to make it possible to require a WindowsConsoleIO instance to talk to a file (which then could not use WriteConsoleW I believe, though it may be possible to trick it).

It's a harmless enough issue that I think we're okay. Misunderstanding the UTF-8 format is what the problem was this time, and that's been triple checked now.

@serhiy-storchaka

Copy link
Copy Markdown
Member

I'm just wondering if it's possible to get invalid UTF-8 here (using "surrogateescape"?). If yes, then we should use more sophisticated way to find the longest valid prefix of invalid sequence to meet recomendations for handling invalid UTF-8. Otherwise LGTM.

@zooba

Copy link
Copy Markdown
Member

If it's undecodable by MultiByteToWideChar at this point, we'll have raised an error and never entered into this branch (wlen will be 0). And even if it did, it wouldn't be rendered correctly anyway and we aren't really making things worse by rendering it slightly more incorrectly.

Thanks for the review!

@zooba
zooba merged commit 11312ea into python:mainOct 20, 2023
@miss-islington-app

Copy link
Copy Markdown

Thanks @sorgloomer for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 20, 2023
…H-111007)
(cherry picked from commit 11312ea)
Co-authored-by: Tamás Hegedűs <sorgloomer@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 20, 2023
…H-111007)
(cherry picked from commit 11312ea)
Co-authored-by: Tamás Hegedűs <sorgloomer@users.noreply.github.com>
@bedevere-app

Copy link
Copy Markdown

GH-111108 is a backport of this pull request to the 3.12 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.12 only security fixes label Oct 20, 2023
@bedevere-app

Copy link
Copy Markdown

GH-111109 is a backport of this pull request to the 3.11 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.11 only security fixes label Oct 20, 2023
zooba pushed a commit that referenced this pull request Oct 20, 2023
(cherry picked from commit 11312ea)
Co-authored-by: Tamás Hegedűs <sorgloomer@users.noreply.github.com>
zooba pushed a commit that referenced this pull request Oct 20, 2023
(cherry picked from commit 11312ea)
Co-authored-by: Tamás Hegedűs <sorgloomer@users.noreply.github.com>
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@sorgloomer@zooba@serhiy-storchaka