Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions stl/src/xmbtowc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ _MRTIMP2 _Success_(return >= 0) int __cdecl _Mbrtowc(
}
}

if ((consumedCount == 2 && wch < 0x80u) || (consumedCount == 3 && wch < 0x800u)) { // overlong forms
errno = EILSEQ;
return -1;
}

if (wch >= 0xD800u && wch <= 0xDFFFu) { // tried to decode unpaired surrogate
errno = EILSEQ;
return -1;
Expand Down
13 changes: 12 additions & 1 deletion tests/std/tests/VSO_0644691_utf_8_codecvt/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const encoding_test_char utf_test_cases[] = {
{"\xED\x9F\xBF", L"\uD7FF"}, // U+D7FF unencoded from the Hangul Jamo Extended-B block,
// last character before UTF-16 illegal region
{"\xED\xA0\x80", nullptr}, // U+D800 beginning of surrogate range
{nullptr, L"\xD800"},
{nullptr, L"\xD800"}, //
{"\xED\xBF\xBF", nullptr}, // U+DFFF end of surrogate range
{nullptr, L"\xDFFF"},
{"\xEE\x80\x80", L"\uE000"}, // U+E000 unencoded from the private use area, first codepoint after surrogate range
Expand All @@ -48,6 +48,17 @@ const encoding_test_char utf_test_cases[] = {
// ^^^ TRANSITION, VSO-653059 ^^^
{"\xC2\x61", nullptr}, // Wrong number of trailing bytes
{"\xE0\xA0\x61", nullptr},

{"\xC0\x80", nullptr}, // overlong form: 2 bytes for U+0000 NULL
{"\xC0\x81", nullptr}, // overlong form: 2 bytes for U+0001 START OF HEADING

{"\xC1\xBF", nullptr}, // overlong form: 2 bytes for U+007F DELETE
{"\xE0\x81\xBF", nullptr}, // overlong form: 3 bytes for U+007F DELETE
{"\xF0\x80\x81\xBF", nullptr}, // overlong form: 4 bytes for U+007F DELETE

{"\xD0\xAF", L"\u042F"}, // U+042F CYRILLIC CAPITAL LETTER YA
{"\xE0\x90\xAF", nullptr}, // overlong form: 3 bytes for U+042F CYRILLIC CAPITAL LETTER YA
{"\xF0\x80\x90\xAF", nullptr}, // overlong form: 4 bytes for U+042F CYRILLIC CAPITAL LETTER YA
};

void assert_empty_file(const wchar_t* const fileName) {
Expand Down