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

Side by Side Diff: src/wasm/decoder.h

Issue 1743773002: WebAssembly: skip unknown sections, add names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix limit type Created 4 years, 9 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
« no previous file with comments | « no previous file | src/wasm/module-decoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 #ifndef V8_WASM_DECODER_H_ 5 #ifndef V8_WASM_DECODER_H_
6 #define V8_WASM_DECODER_H_ 6 #define V8_WASM_DECODER_H_
7 7
8 #include "src/base/smart-pointers.h" 8 #include "src/base/smart-pointers.h"
9 #include "src/flags.h" 9 #include "src/flags.h"
10 #include "src/signature.h" 10 #include "src/signature.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 if (pc_ == end && (b & 0x80)) { 224 if (pc_ == end && (b & 0x80)) {
225 error(pc_ - 1, "varint too large"); 225 error(pc_ - 1, "varint too large");
226 } else { 226 } else {
227 TRACE("= %u\n", result); 227 TRACE("= %u\n", result);
228 } 228 }
229 return result; 229 return result;
230 } 230 }
231 return traceOffEnd<uint32_t>(); 231 return traceOffEnd<uint32_t>();
232 } 232 }
233 233
234 // Consume {size} bytes and send them to the bit bucket, advancing {pc_}.
235 void consume_bytes(int size) {
236 if (checkAvailable(size)) {
237 pc_ += size;
238 } else {
239 pc_ = limit_;
240 }
241 }
242
234 // Check that at least {size} bytes exist between {pc_} and {limit_}. 243 // Check that at least {size} bytes exist between {pc_} and {limit_}.
235 bool checkAvailable(int size) { 244 bool checkAvailable(int size) {
236 if (pc_ < start_ || (pc_ + size) > limit_) { 245 intptr_t pc_overflow_value = std::numeric_limits<intptr_t>::max() - size;
246 if (size < 0 || (intptr_t)pc_ > pc_overflow_value) {
247 error(pc_, nullptr, "reading %d bytes would underflow/overflow", size);
248 return false;
249 } else if (pc_ < start_ || limit_ < (pc_ + size)) {
237 error(pc_, nullptr, "expected %d bytes, fell off end", size); 250 error(pc_, nullptr, "expected %d bytes, fell off end", size);
238 return false; 251 return false;
239 } else { 252 } else {
240 return true; 253 return true;
241 } 254 }
242 } 255 }
243 256
244 void error(const char* msg) { error(pc_, nullptr, msg); } 257 void error(const char* msg) { error(pc_, nullptr, msg); }
245 258
246 void error(const byte* pc, const char* msg) { error(pc, nullptr, msg); } 259 void error(const byte* pc, const char* msg) { error(pc, nullptr, msg); }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 return result; 379 return result;
367 } 380 }
368 }; 381 };
369 382
370 #undef TRACE 383 #undef TRACE
371 } // namespace wasm 384 } // namespace wasm
372 } // namespace internal 385 } // namespace internal
373 } // namespace v8 386 } // namespace v8
374 387
375 #endif // V8_WASM_DECODER_H_ 388 #endif // V8_WASM_DECODER_H_
OLDNEW
« no previous file with comments | « no previous file | src/wasm/module-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698