Add missing check for UTF-16 low surrogate char at start of buffer (dotnet/coreclr...
authorLevi Broderick <GrabYourPitchforks@users.noreply.github.com>
Sat, 27 Apr 2019 21:21:08 +0000 (14:21 -0700)
committerGitHub <noreply@github.com>
Sat, 27 Apr 2019 21:21:08 +0000 (14:21 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/b7fc495f951ced0c6fa1207353bf5c2aa2d058df

src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf16Utility.Validation.cs

index d398c1f..b1215f4 100644 (file)
@@ -325,6 +325,11 @@ namespace System.Text.Unicode
                             // or palignr available to us, we'll do this as a loop. We won't look at
                             // the very last high surrogate char element since we don't yet know if
                             // the next vector read will have a low surrogate char element.
+                            
+                            if (lowSurrogateChars[0] != 0)
+                            {
+                                goto Error; // error: start of buffer contains standalone low surrogate char
+                            }
 
                             ushort surrogatePairsCount = 0;
                             for (int i = 0; i < Vector<ushort>.Count - 1; i++)