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

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: add titzer's comments 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') | src/wasm/utf8.h » ('J')
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..650ef047977486d6b1f635137f3f53adcb9e23d1 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;
+
+ // Preformance optimization: Skip over single-byte values first.
titzer 2016/05/12 11:35:30 s/Preformance/Performance/
Clemens Hammacher 2016/05/12 11:48:26 Done.
+ 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') | src/wasm/utf8.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698