Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(679)

Unified Diff: src/unicode.cc

Issue 1967023004: [wasm] Add UTF-8 validation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase on parallel compilation Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/unicode.h ('k') | src/unicode-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/unicode.cc
diff --git a/src/unicode.cc b/src/unicode.cc
index de5e36038b3412f85a580d77203bdf74abd23fa7..db98be867579740b0e599c84c5b8fc164d834665 100644
--- a/src/unicode.cc
+++ b/src/unicode.cc
@@ -305,6 +305,20 @@ uchar Utf8::CalculateValue(const byte* str, size_t max_length, size_t* cursor) {
0x03C82080;
}
+bool Utf8::Validate(const byte* bytes, size_t length) {
+ size_t cursor = 0;
+
+ // Performance optimization: Skip over single-byte values first.
+ while (cursor < length && bytes[cursor] <= kMaxOneByteChar) {
+ ++cursor;
+ }
+
+ while (cursor < length) {
+ uchar c = ValueOf(bytes + cursor, length - cursor, &cursor);
+ if (!IsValidCharacter(c)) return false;
+ }
+ return true;
+}
// Uppercase: point.category == 'Lu'
« no previous file with comments | « src/unicode.h ('k') | src/unicode-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698