Skip to content

Allow valid UTF-8 replacement characters in flutter_tools decoding - #188901

Merged
auto-submit[bot] merged 3 commits into
flutter:masterfrom
LinXunFeng:fix/flutter-tools-valid-replacement-character-utf8
Aug 5, 2026
Merged

auto-submit[bot] merged 3 commits into
flutter:masterfrom
LinXunFeng:fix/flutter-tools-valid-replacement-character-utf8

Conversation

@LinXunFeng

Copy link
Copy Markdown
Member

Fixes #177509

This updates flutter_tools UTF-8 error detection so that a valid U+FFFD replacement character is not mistaken for malformed UTF-8.

Previously, Utf8Decoder decoded bytes with allowMalformed: true and then treated any decoded string containing U+FFFD as evidence that the original bytes were malformed. That incorrectly rejects valid UTF-8 input such as EF BF BD, which is the legitimate encoding of U+FFFD.

This PR changes the decoder to use a strict UTF-8 decoder when reportErrors is enabled. If strict decoding succeeds, the decoded string is returned as-is. If strict decoding throws FormatException, the input is decoded again with allowMalformed: true only to preserve the existing ToolExit diagnostic message and source bytes.

The permissive reportErrors: false path is unchanged and continues to decode malformed bytes with replacement characters.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jul 2, 2026
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jul 2, 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 Utf8Decoder to use a strict UTF-8 decoder when reportErrors is enabled, catching FormatException during direct conversion to throw a descriptive ToolExit. It also adds tests to verify decoding behavior with valid replacement characters and malformed bytes. Feedback indicates a potential regression where using the strict decoder for chunked conversion, stream binding, and fusing could cause unhandled FormatException crashes, as these paths lack the error-handling wrapper implemented in the convert method.

Comment thread packages/flutter_tools/lib/src/convert.dart Outdated
@bkonyi
bkonyi requested review from bkonyi and chingjun August 5, 2026 14:43

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

Thanks for the contribution! LGTM!

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

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[web]: Unicode char in print statement throws Bad UTF-8 encoding (U+FFFD; REPLACEMENT CHARACTER) error

3 participants