Skip to content

avoid partial UTF-8 sequences in wide-string AppendTruncated#2119

Open
nabhan06 wants to merge 1 commit into
abseil:masterfrom
nabhan06:log-wide-surrogate-truncation
Open

avoid partial UTF-8 sequences in wide-string AppendTruncated#2119
nabhan06 wants to merge 1 commit into
abseil:masterfrom
nabhan06:log-wide-surrogate-truncation

Conversation

@nabhan06

Copy link
Copy Markdown
Contributor

AppendTruncated encodes each wchar_t with WideToUtf8, which splits a surrogate pair across two calls and emits only the first two bytes of a four-byte sequence for the high half. Nothing checks that the pair completes, so a trailing unpaired high surrogate, a high surrogate followed by any other unit, or a valid pair straddling the truncation boundary each leave a partial sequence in the log record. This encodes U+FFFD for an unpaired high surrogate and lets a pending low surrogate use the two bytes its high half already reserved; the new test covers all three cases and fails on each without the fix.

EXPECT_EQ(Append(src, 4), "a");
}

TEST(AppendTruncatedTest, PlainCharactersAreUnaffected) {

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.

This test appears to be broken on windows

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.

4 participants