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

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

Issue 2657463003: [wasm] Errors in names section do not fail the whole module. (Closed)
Patch Set: Added a TODO Created 3 years, 10 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 <memory> 8 #include <memory>
9 9
10 #include "src/base/compiler-specific.h" 10 #include "src/base/compiler-specific.h"
(...skipping 19 matching lines...) Expand all
30 // A helper utility to decode bytes, integers, fields, varints, etc, from 30 // A helper utility to decode bytes, integers, fields, varints, etc, from
31 // a buffer of bytes. 31 // a buffer of bytes.
32 class Decoder { 32 class Decoder {
33 public: 33 public:
34 Decoder(const byte* start, const byte* end) 34 Decoder(const byte* start, const byte* end)
35 : start_(start), 35 : start_(start),
36 pc_(start), 36 pc_(start),
37 end_(end), 37 end_(end),
38 error_pc_(nullptr), 38 error_pc_(nullptr),
39 error_pt_(nullptr) {} 39 error_pt_(nullptr) {}
40 Decoder(const byte* start, const byte* pc, const byte* end)
41 : start_(start),
42 pc_(pc),
43 end_(end),
44 error_pc_(nullptr),
45 error_pt_(nullptr) {}
40 46
41 virtual ~Decoder() {} 47 virtual ~Decoder() {}
42 48
43 inline bool check(const byte* base, unsigned offset, unsigned length, 49 inline bool check(const byte* base, unsigned offset, unsigned length,
44 const char* msg) { 50 const char* msg) {
45 DCHECK_GE(base, start_); 51 DCHECK_GE(base, start_);
46 if ((base + offset + length) > end_) { 52 if ((base + offset + length) > end_) {
47 error(base, base + offset, "%s", msg); 53 error(base, base + offset, "%s", msg);
48 return false; 54 return false;
49 } 55 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 return consume_leb<uint32_t, false>(name); 183 return consume_leb<uint32_t, false>(name);
178 } 184 }
179 185
180 // Reads a LEB128 variable-length signed 32-bit integer and advances {pc_}. 186 // Reads a LEB128 variable-length signed 32-bit integer and advances {pc_}.
181 int32_t consume_i32v(const char* name = nullptr) { 187 int32_t consume_i32v(const char* name = nullptr) {
182 return consume_leb<int32_t, true>(name); 188 return consume_leb<int32_t, true>(name);
183 } 189 }
184 190
185 // Consume {size} bytes and send them to the bit bucket, advancing {pc_}. 191 // Consume {size} bytes and send them to the bit bucket, advancing {pc_}.
186 void consume_bytes(uint32_t size, const char* name = "skip") { 192 void consume_bytes(uint32_t size, const char* name = "skip") {
187 TRACE(" +%d %-20s: %d bytes\n", static_cast<int>(pc_ - start_), name, 193 #if DEBUG
188 size); 194 if (name) {
195 // Only trace if the name is not null.
196 TRACE(" +%d %-20s: %d bytes\n", static_cast<int>(pc_ - start_), name,
197 size);
198 }
199 #endif
189 if (checkAvailable(size)) { 200 if (checkAvailable(size)) {
190 pc_ += size; 201 pc_ += size;
191 } else { 202 } else {
192 pc_ = end_; 203 pc_ = end_;
193 } 204 }
194 } 205 }
195 206
196 // Check that at least {size} bytes exist between {pc_} and {end_}. 207 // Check that at least {size} bytes exist between {pc_} and {end_}.
197 bool checkAvailable(int size) { 208 bool checkAvailable(int size) {
198 intptr_t pc_overflow_value = std::numeric_limits<intptr_t>::max() - size; 209 intptr_t pc_overflow_value = std::numeric_limits<intptr_t>::max() - size;
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 return traceOffEnd<uint32_t>(); 400 return traceOffEnd<uint32_t>();
390 } 401 }
391 }; 402 };
392 403
393 #undef TRACE 404 #undef TRACE
394 } // namespace wasm 405 } // namespace wasm
395 } // namespace internal 406 } // namespace internal
396 } // namespace v8 407 } // namespace v8
397 408
398 #endif // V8_WASM_DECODER_H_ 409 #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