Skip to content

[Engine] Fix silent buffer mismatch bug in FML Win32 CommandLineFromPlatform#187120

Merged
auto-submit[bot] merged 1 commit into
flutter:masterfrom
bkonyi:fix-fml-windows-utf8-paths
May 27, 2026
Merged

[Engine] Fix silent buffer mismatch bug in FML Win32 CommandLineFromPlatform#187120
auto-submit[bot] merged 1 commit into
flutter:masterfrom
bkonyi:fix-fml-windows-utf8-paths

Conversation

@bkonyi

@bkonyi bkonyi commented May 26, 2026

Copy link
Copy Markdown
Contributor

Description

This pull request resolves a critical, long-standing C++ bug inside FML's Windows platform CommandLineFromPlatform command-line parser that caused all wide-character UTF-8 command arguments to be silently discarded and corrupted.

  • The Bug: In fml/platform/win/command_line_win.cc, WideCharToMultiByte was being passed -1 as the input length (cbMultiByte) inside the string conversion loop. This instructed the Win32 API to write the converted UTF-8 string plus an extra null terminator. However, the pre-allocated buffer size utf8_arg only had space for arg_len (which excludes the null terminator). Consequently, the Win32 API failed with ERROR_INSUFFICIENT_BUFFER and returned 0, leaving the string argument completely empty or corrupted.
  • The Fallback & Crash: Due to this silent conversion failure, the FML parser always fell back to standard narrow-character command-line arguments (argc/argv). This caused all non-ASCII (UTF-8) characters in paths (such as usernames containing accented letters like Jérôme or East Asian characters) to be corrupted. Downstream compiled tools like impellerc (the Impeller shader compiler) received these corrupted paths and crashed with ShaderCompilerException (exit code -1073741819 Access Violation / Segmentation Fault) when compiling Material Design shaders.
  • The Fix: Resolves the buffer mismatch by passing wcslen(arg) to the second WideCharToMultiByte call, matching the pre-allocated buffer size perfectly and ensuring that all UTF-8 wide paths are correctly preserved and parsed on Windows.

Fixes #186955

@bkonyi bkonyi added the team-tool Owned by Flutter Tool team label May 26, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 26, 2026
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. and removed team-tool Owned by Flutter Tool team labels May 26, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates command_line_win.cc to pass the correct argument length to WideCharToMultiByte instead of -1. A review comment suggests storing the result of wcslen(arg) in a local variable to avoid redundant computations and using it to prevent implicit narrowing conversion warnings, aligning with the Google C++ Style Guide.

Comment thread engine/src/flutter/fml/platform/win/command_line_win.cc Outdated
@bkonyi bkonyi force-pushed the fix-fml-windows-utf8-paths branch from 1481f88 to 8b10c24 Compare May 26, 2026 19:47
@github-actions github-actions Bot removed the CICD Run CI/CD label May 26, 2026
@bkonyi bkonyi force-pushed the fix-fml-windows-utf8-paths branch from 8b10c24 to ce885fd Compare May 26, 2026 19:50
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 26, 2026
@bkonyi bkonyi requested a review from gaaclarke May 26, 2026 20:27
gaaclarke
gaaclarke previously approved these changes May 26, 2026

@gaaclarke gaaclarke 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.

lgtm, thanks!

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label May 26, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 26, 2026
@auto-submit

auto-submit Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/187120, because - The status or check suite Linux linux_host_engine_test has failed. Please fix the issues identified (or deflake) before re-applying this label.

  • The status or check suite Linux linux_fuchsia_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.

@bkonyi bkonyi force-pushed the fix-fml-windows-utf8-paths branch from ce885fd to f4abeac Compare May 26, 2026 20:39
@github-actions github-actions Bot removed the CICD Run CI/CD label May 26, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 26, 2026
…latform

Resolves a critical, long-standing bug inside FML's Windows platform CommandLineFromPlatform command-line parser.
On Windows, the wide-character to UTF-8 converter (WideCharToMultiByte) was being passed -1 as the cbMultiByte count, causing it to attempt to write the converted arguments plus an extra null terminator. However, the pre-allocated buffer size only had space for the non-null terminated string length (arg_len), causing the Win32 API to fail with ERROR_INSUFFICIENT_BUFFER and silently return an empty string.

As a result, the command line parser would silently fail on Windows and fall back to standard narrow-character command-line arguments (argc/argv). This caused all non-ASCII (UTF-8) characters in paths (such as user names like 'Jérôme') to be permanently corrupted, subsequently crashing downstream compiled tools like impellerc (the Impeller shader compiler) with unhandled ShaderCompilerException (exit code -1073741819) during Material design shader builds.

This C++ engine-level fix resolves the buffer mismatch by passing wcslen(arg) to WideCharToMultiByte, matching the pre-allocated buffer size perfectly and ensuring that all UTF-8 wide paths are correctly preserved and parsed on Windows.

Fixes flutter#186955

TAG=agy
CONV=aecb9c22-0b32-40b6-9bf0-51bb472c408d
@bkonyi bkonyi force-pushed the fix-fml-windows-utf8-paths branch from f4abeac to 079e1c5 Compare May 26, 2026 21:49
@bkonyi bkonyi added CICD Run CI/CD and removed CICD Run CI/CD labels May 26, 2026
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label May 26, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue May 27, 2026
Merged via the queue into flutter:master with commit e440052 May 27, 2026
207 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 27, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request May 27, 2026
flutter/flutter@f3a4b98...c8f2f16

2026-05-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Flutter GPU] Add explicit draw counts (#186639)" (flutter/flutter#187170)
2026-05-27 engine-flutter-autoroll@skia.org Roll Dart SDK from 7dcea971af6b to f3db7b7d9801 (2 revisions) (flutter/flutter#187144)
2026-05-27 bdero@google.com [Flutter GPU] Add explicit draw counts (flutter/flutter#186639)
2026-05-27 engine-flutter-autoroll@skia.org Roll Skia from f9db7748563e to fa944af10f91 (1 revision) (flutter/flutter#187139)
2026-05-27 bdero@google.com [Flutter GPU] Flutter GPU ShaderLibrary in-place reload for shader hot reload (flutter/flutter#186793)
2026-05-27 engine-flutter-autoroll@skia.org Roll Skia from a692cbf38952 to f9db7748563e (8 revisions) (flutter/flutter#187135)
2026-05-27 burak.karahan@mail.ru Use local semantics tester in Material button tests (flutter/flutter#186667)
2026-05-27 rmolivares@renzo-olivares.dev Filter out `a: text input` from `team-framework` PR triage  (flutter/flutter#187129)
2026-05-27 bkonyi@google.com [Engine] Fix silent buffer mismatch bug in FML Win32 CommandLineFromPlatform (flutter/flutter#187120)
2026-05-27 srawlins@google.com examples: Remove unused parameters (flutter/flutter#185819)
2026-05-27 116356835+AbdeMohlbi@users.noreply.github.com Remove another `String.valueOf` (flutter/flutter#186628)
2026-05-27 alex.medinsh@gmail.com Print trace when skipping flavor-specific and platform-specific assets (flutter/flutter#187045)
2026-05-26 adilhanney@disroot.org Fix `InteractiveViewer` memory leak from undisposed `CurvedAnimation`s (flutter/flutter#185826)
2026-05-26 meylis@divine.video Fix AccessibilityBridge startup crash on vendor-modified Android (flutter/flutter#184630)
2026-05-26 keertip@users.noreply.github.com Update data driven fixes docs (flutter/flutter#186217)
2026-05-26 ahmedsameha1@gmail.com Add more 0x0 size tests part10 (flutter/flutter#186201)
2026-05-26 46920873+gabrimatic@users.noreply.github.com Disable spell check for obscured text (flutter/flutter#186329)
2026-05-26 chris@bracken.jp [iOS] Migrate VSyncClient and DisplayLinkManager to Swift (flutter/flutter#187001)
2026-05-26 bkonyi@google.com [flutter_tools, devicelab] Add safety filesystem guard to tests (flutter/flutter#186748)
2026-05-26 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from Itd2Jq_ZIABH2rW7B... to k9EizfEGJO4WwQN9-... (flutter/flutter#187115)
2026-05-26 engine-flutter-autoroll@skia.org Roll Dart SDK from 00e625453c43 to 7dcea971af6b (1 revision) (flutter/flutter#187117)
2026-05-26 rmacnak@google.com Remove use of deprecated copy_trees. (flutter/flutter#187091)
2026-05-26 15619084+vashworth@users.noreply.github.com Use resolved implementation plugins with SwiftPM (flutter/flutter#187097)
2026-05-26 engine-flutter-autoroll@skia.org Roll Skia from 27a819894f7c to a692cbf38952 (3 revisions) (flutter/flutter#187109)
2026-05-26 engine-flutter-autoroll@skia.org Roll Packages from 69cf959 to fc795e5 (4 revisions) (flutter/flutter#187114)
2026-05-26 mvincentong@gmail.com Handle simctl process exceptions during discovery (flutter/flutter#186501)
2026-05-26 mvincentong@gmail.com Clarify precache enabled platforms help (flutter/flutter#186878)
2026-05-26 bkonyi@google.com [tool] Refactor artifacts.dart to use enhanced enums and reduce duplication (flutter/flutter#187063)
2026-05-26 jason-simmons@users.noreply.github.com Build script updates for syncing engine sources and building artifacts on linux-arm64 (flutter/flutter#186917)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC boetger@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…r#11795)

flutter/flutter@f3a4b98...c8f2f16

2026-05-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Flutter GPU] Add explicit draw counts (#186639)" (flutter/flutter#187170)
2026-05-27 engine-flutter-autoroll@skia.org Roll Dart SDK from 7dcea971af6b to f3db7b7d9801 (2 revisions) (flutter/flutter#187144)
2026-05-27 bdero@google.com [Flutter GPU] Add explicit draw counts (flutter/flutter#186639)
2026-05-27 engine-flutter-autoroll@skia.org Roll Skia from f9db7748563e to fa944af10f91 (1 revision) (flutter/flutter#187139)
2026-05-27 bdero@google.com [Flutter GPU] Flutter GPU ShaderLibrary in-place reload for shader hot reload (flutter/flutter#186793)
2026-05-27 engine-flutter-autoroll@skia.org Roll Skia from a692cbf38952 to f9db7748563e (8 revisions) (flutter/flutter#187135)
2026-05-27 burak.karahan@mail.ru Use local semantics tester in Material button tests (flutter/flutter#186667)
2026-05-27 rmolivares@renzo-olivares.dev Filter out `a: text input` from `team-framework` PR triage  (flutter/flutter#187129)
2026-05-27 bkonyi@google.com [Engine] Fix silent buffer mismatch bug in FML Win32 CommandLineFromPlatform (flutter/flutter#187120)
2026-05-27 srawlins@google.com examples: Remove unused parameters (flutter/flutter#185819)
2026-05-27 116356835+AbdeMohlbi@users.noreply.github.com Remove another `String.valueOf` (flutter/flutter#186628)
2026-05-27 alex.medinsh@gmail.com Print trace when skipping flavor-specific and platform-specific assets (flutter/flutter#187045)
2026-05-26 adilhanney@disroot.org Fix `InteractiveViewer` memory leak from undisposed `CurvedAnimation`s (flutter/flutter#185826)
2026-05-26 meylis@divine.video Fix AccessibilityBridge startup crash on vendor-modified Android (flutter/flutter#184630)
2026-05-26 keertip@users.noreply.github.com Update data driven fixes docs (flutter/flutter#186217)
2026-05-26 ahmedsameha1@gmail.com Add more 0x0 size tests part10 (flutter/flutter#186201)
2026-05-26 46920873+gabrimatic@users.noreply.github.com Disable spell check for obscured text (flutter/flutter#186329)
2026-05-26 chris@bracken.jp [iOS] Migrate VSyncClient and DisplayLinkManager to Swift (flutter/flutter#187001)
2026-05-26 bkonyi@google.com [flutter_tools, devicelab] Add safety filesystem guard to tests (flutter/flutter#186748)
2026-05-26 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from Itd2Jq_ZIABH2rW7B... to k9EizfEGJO4WwQN9-... (flutter/flutter#187115)
2026-05-26 engine-flutter-autoroll@skia.org Roll Dart SDK from 00e625453c43 to 7dcea971af6b (1 revision) (flutter/flutter#187117)
2026-05-26 rmacnak@google.com Remove use of deprecated copy_trees. (flutter/flutter#187091)
2026-05-26 15619084+vashworth@users.noreply.github.com Use resolved implementation plugins with SwiftPM (flutter/flutter#187097)
2026-05-26 engine-flutter-autoroll@skia.org Roll Skia from 27a819894f7c to a692cbf38952 (3 revisions) (flutter/flutter#187109)
2026-05-26 engine-flutter-autoroll@skia.org Roll Packages from 69cf959 to fc795e5 (4 revisions) (flutter/flutter#187114)
2026-05-26 mvincentong@gmail.com Handle simctl process exceptions during discovery (flutter/flutter#186501)
2026-05-26 mvincentong@gmail.com Clarify precache enabled platforms help (flutter/flutter#186878)
2026-05-26 bkonyi@google.com [tool] Refactor artifacts.dart to use enhanced enums and reduce duplication (flutter/flutter#187063)
2026-05-26 jason-simmons@users.noreply.github.com Build script updates for syncing engine sources and building artifacts on linux-arm64 (flutter/flutter#186917)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC boetger@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
via-guy pushed a commit to via-guy/flutter that referenced this pull request Jun 26, 2026
…latform (flutter#187120)

### Description
This pull request resolves a critical, long-standing C++ bug inside
FML's Windows platform `CommandLineFromPlatform` command-line parser
that caused all wide-character UTF-8 command arguments to be silently
discarded and corrupted.

* **The Bug:** In `fml/platform/win/command_line_win.cc`,
`WideCharToMultiByte` was being passed `-1` as the input length
(cbMultiByte) inside the string conversion loop. This instructed the
Win32 API to write the converted UTF-8 string *plus* an extra null
terminator. However, the pre-allocated buffer size `utf8_arg` only had
space for `arg_len` (which excludes the null terminator). Consequently,
the Win32 API failed with `ERROR_INSUFFICIENT_BUFFER` and returned `0`,
leaving the string argument completely empty or corrupted.
* **The Fallback & Crash:** Due to this silent conversion failure, the
FML parser always fell back to standard narrow-character command-line
arguments (`argc/argv`). This caused all non-ASCII (UTF-8) characters in
paths (such as usernames containing accented letters like `Jérôme` or
East Asian characters) to be corrupted. Downstream compiled tools like
`impellerc` (the Impeller shader compiler) received these corrupted
paths and crashed with `ShaderCompilerException` (exit code
`-1073741819` Access Violation / Segmentation Fault) when compiling
Material Design shaders.
* **The Fix:** Resolves the buffer mismatch by passing `wcslen(arg)` to
the second `WideCharToMultiByte` call, matching the pre-allocated buffer
size perfectly and ensuring that all UTF-8 wide paths are correctly
preserved and parsed on Windows.

Fixes flutter#186955
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tool_crash] ShaderCompilerException at ShaderCompiler.compileShader on Windows/Linux due to UTF-8 paths or MAX_PATH

2 participants