Skip to content
Open
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
6 changes: 6 additions & 0 deletions stl/src/xmbtowc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ _MRTIMP2 _Success_(return >= 0) int __cdecl _Mbrtowc(
}
}

// Reject overlong forms and out-of-range code points (see N4950 [locale.codecvt.virtuals]/3)
if ((consumedCount == 2 && wch < 0x80u) || (consumedCount == 3 && wch < 0x800u) || wch > 0x10FFFFu) {
errno = EILSEQ;
return -1;
}

if (wch >= 0xD800u && wch <= 0xDFFFu) { // tried to decode unpaired surrogate
errno = EILSEQ;
return -1;
Expand Down