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

Unified Diff: src/wasm/module-decoder.cc

Issue 2310023002: [wasm] Validate the length of strings before validating the string. (Closed)
Patch Set: Created 4 years, 3 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 | « no previous file | test/unittests/wasm/module-decoder-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/module-decoder.cc
diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc
index 09b52a45c5b32da638a3adbe0bf0d75869e700e2..bb5d7345142ec7fa04f5a79ece2f9e3e66129e54 100644
--- a/src/wasm/module-decoder.cc
+++ b/src/wasm/module-decoder.cc
@@ -585,9 +585,13 @@ class ModuleDecoder : public Decoder {
// the offset of the string, and the length as an out parameter.
uint32_t consume_string(uint32_t* length, bool validate_utf8) {
*length = consume_u32v("string length");
+ // Check if the string does not exceed module boundaries.
+ if (pc_ + *length >= end_) {
titzer 2016/09/06 09:02:33 This can wrap around. There should be sufficient c
ahaas 2016/09/06 09:22:12 Done.
+ error(pc_, "invalid string length");
+ }
uint32_t offset = pc_offset();
TRACE(" +%u %-20s: (%u bytes)\n", offset, "string", *length);
- if (validate_utf8 && !unibrow::Utf8::Validate(pc_, *length)) {
+ if (ok() && validate_utf8 && !unibrow::Utf8::Validate(pc_, *length)) {
error(pc_, "no valid UTF-8 string");
}
consume_bytes(*length);
« no previous file with comments | « no previous file | test/unittests/wasm/module-decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698