Skip to content

fix(error-code): sanitize non-UTF-8 bytes from ec.message() (fixes #4436) - #4918

Closed
yunaremaia wants to merge 1 commit into
fmtlib:mainfrom
yunaremaia:fix/error-code-encoding
Closed

fix(error-code): sanitize non-UTF-8 bytes from ec.message() (fixes #4436)#4918
yunaremaia wants to merge 1 commit into
fmtlib:mainfrom
yunaremaia:fix/error-code-encoding

Conversation

@yunaremaia

Copy link
Copy Markdown

On Windows, std::error_code::message() may return a string in a system code page (e.g. CP-1252) containing bytes invalid in UTF-8. When formatted with {:s}, this caused encoding errors/crashes (issue #4436).

Adds detail::append_utf8_sanitized() which validates UTF-8 input and replaces invalid byte sequences with U+FFFD (replacement character). The std::error_code formatter now uses this helper instead of appending ec.message() directly.

Test: std_test.error_code includes a direct test of the sanitize helper with non-UTF-8 input. All existing tests pass.

…tlib#4436)

On Windows, std::error_code::message() may return a string in a system
code page (e.g. CP-1252) containing bytes invalid in UTF-8. When formatted
with {:s}, this caused encoding errors / crashes.

Adds detail::append_utf8_sanitized() which validates UTF-8 input and
replaces invalid byte sequences with U+FFFD (replacement character).
The std::error_code formatter now uses this helper instead of appending
ec.message() directly.
@yunaremaia
yunaremaia requested a review from vitaut as a code owner September 4, 2026 00:17
@yunaremaia

Copy link
Copy Markdown
Author

CI hasn't been triggered yet on this PR. Could you re-run the workflow or let me know if there's anything I need to do to trigger CI checks?

@vitaut

vitaut commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR but this would just mask a bug in Microsoft STL, please see #4884 for details.

@vitaut vitaut closed this Sep 5, 2026
Sign up for free to 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.

2 participants