| OLD | NEW |
| 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 #include "src/wasm/module-decoder.h" | 5 #include "src/wasm/module-decoder.h" |
| 6 | 6 |
| 7 #include "src/base/functional.h" | 7 #include "src/base/functional.h" |
| 8 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
| 9 #include "src/macro-assembler.h" | 9 #include "src/macro-assembler.h" |
| 10 #include "src/objects.h" | 10 #include "src/objects.h" |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 } | 580 } |
| 581 return offset; | 581 return offset; |
| 582 } | 582 } |
| 583 | 583 |
| 584 // Reads a length-prefixed string, checking that it is within bounds. Returns | 584 // Reads a length-prefixed string, checking that it is within bounds. Returns |
| 585 // the offset of the string, and the length as an out parameter. | 585 // the offset of the string, and the length as an out parameter. |
| 586 uint32_t consume_string(uint32_t* length, bool validate_utf8) { | 586 uint32_t consume_string(uint32_t* length, bool validate_utf8) { |
| 587 *length = consume_u32v("string length"); | 587 *length = consume_u32v("string length"); |
| 588 uint32_t offset = pc_offset(); | 588 uint32_t offset = pc_offset(); |
| 589 TRACE(" +%u %-20s: (%u bytes)\n", offset, "string", *length); | 589 TRACE(" +%u %-20s: (%u bytes)\n", offset, "string", *length); |
| 590 if (validate_utf8 && !unibrow::Utf8::Validate(pc_, *length)) { | 590 const byte* string_start = pc_; |
| 591 error(pc_, "no valid UTF-8 string"); | 591 // Consume bytes before validation to guarantee that the string is not oob. |
| 592 consume_bytes(*length); |
| 593 if (ok() && validate_utf8 && |
| 594 !unibrow::Utf8::Validate(string_start, *length)) { |
| 595 error(string_start, "no valid UTF-8 string"); |
| 592 } | 596 } |
| 593 consume_bytes(*length); | |
| 594 return offset; | 597 return offset; |
| 595 } | 598 } |
| 596 | 599 |
| 597 uint32_t consume_sig_index(WasmModule* module, FunctionSig** sig) { | 600 uint32_t consume_sig_index(WasmModule* module, FunctionSig** sig) { |
| 598 const byte* pos = pc_; | 601 const byte* pos = pc_; |
| 599 uint32_t sig_index = consume_u32v("signature index"); | 602 uint32_t sig_index = consume_u32v("signature index"); |
| 600 if (sig_index >= module->signatures.size()) { | 603 if (sig_index >= module->signatures.size()) { |
| 601 error(pos, pos, "signature index %u out of bounds (%d signatures)", | 604 error(pos, pos, "signature index %u out of bounds (%d signatures)", |
| 602 sig_index, static_cast<int>(module->signatures.size())); | 605 sig_index, static_cast<int>(module->signatures.size())); |
| 603 *sig = nullptr; | 606 *sig = nullptr; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 decoder.consume_bytes(size); | 817 decoder.consume_bytes(size); |
| 815 } | 818 } |
| 816 if (decoder.more()) decoder.error("unexpected additional bytes"); | 819 if (decoder.more()) decoder.error("unexpected additional bytes"); |
| 817 | 820 |
| 818 return decoder.toResult(std::move(table)); | 821 return decoder.toResult(std::move(table)); |
| 819 } | 822 } |
| 820 | 823 |
| 821 } // namespace wasm | 824 } // namespace wasm |
| 822 } // namespace internal | 825 } // namespace internal |
| 823 } // namespace v8 | 826 } // namespace v8 |
| OLD | NEW |