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

Side by Side Diff: src/wasm/wasm-function-name-table.cc

Issue 1967023004: [wasm] Add UTF-8 validation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix signed/unsigned mismatch 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/wasm/wasm-function-name-table.h" 5 #include "src/wasm/wasm-function-name-table.h"
6 6
7 #include "src/wasm/utf8.h"
7 #include "src/wasm/wasm-module.h" 8 #include "src/wasm/wasm-module.h"
8 9
9 namespace v8 { 10 namespace v8 {
10 namespace internal { 11 namespace internal {
11 namespace wasm { 12 namespace wasm {
12 13
13 // Build an array with all function names. If there are N functions in the 14 // Build an array with all function names. If there are N functions in the
14 // module, then the first (kIntSize * (N+1)) bytes are integer entries. 15 // module, then the first (kIntSize * (N+1)) bytes are integer entries.
15 // The first integer entry encodes the number of functions in the module. 16 // The first integer entry encodes the number of functions in the module.
16 // The entries 1 to N contain offsets into the second part of this array. 17 // The entries 1 to N contain offsets into the second part of this array.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 auto undefined = [&func_names_array]() -> Handle<Object> { 54 auto undefined = [&func_names_array]() -> Handle<Object> {
54 return func_names_array->GetIsolate()->factory()->undefined_value(); 55 return func_names_array->GetIsolate()->factory()->undefined_value();
55 }; 56 };
56 if (func_index >= num_funcs) return undefined(); 57 if (func_index >= num_funcs) return undefined();
57 int offset = func_names_array->get_int(func_index + 1); 58 int offset = func_names_array->get_int(func_index + 1);
58 int next_offset = func_index == num_funcs - 1 59 int next_offset = func_index == num_funcs - 1
59 ? func_names_array->length() 60 ? func_names_array->length()
60 : func_names_array->get_int(func_index + 2); 61 : func_names_array->get_int(func_index + 2);
61 ScopedVector<byte> buffer(next_offset - offset); 62 ScopedVector<byte> buffer(next_offset - offset);
62 func_names_array->copy_out(offset, buffer.start(), next_offset - offset); 63 func_names_array->copy_out(offset, buffer.start(), next_offset - offset);
64 if (!IsValidUtf8(buffer.start(), buffer.length())) return undefined();
63 MaybeHandle<Object> maybe_name = 65 MaybeHandle<Object> maybe_name =
64 func_names_array->GetIsolate()->factory()->NewStringFromUtf8( 66 func_names_array->GetIsolate()->factory()->NewStringFromUtf8(
65 Vector<const char>::cast(buffer)); 67 Vector<const char>::cast(buffer));
66 return maybe_name.is_null() ? undefined() : maybe_name.ToHandleChecked(); 68 return maybe_name.is_null() ? undefined() : maybe_name.ToHandleChecked();
67 } 69 }
68 70
69 } // namespace wasm 71 } // namespace wasm
70 } // namespace internal 72 } // namespace internal
71 } // namespace v8 73 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698