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

Unified Diff: src/wasm/ast-decoder.h

Issue 2052623003: [wasm] improve handling of malformed input (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 4 years, 6 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 | src/wasm/ast-decoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/ast-decoder.h
diff --git a/src/wasm/ast-decoder.h b/src/wasm/ast-decoder.h
index dd8bda811cc08bc3a447764c5e5a11d3f027a29e..27170dd26981ceef93f1044b7747327d9b218942 100644
--- a/src/wasm/ast-decoder.h
+++ b/src/wasm/ast-decoder.h
@@ -25,7 +25,7 @@ namespace wasm {
struct LocalIndexOperand {
uint32_t index;
LocalType type;
- int length;
+ unsigned length;
inline LocalIndexOperand(Decoder* decoder, const byte* pc) {
index = decoder->checked_read_u32v(pc, 1, &length, "local index");
@@ -35,7 +35,7 @@ struct LocalIndexOperand {
struct ImmI8Operand {
int8_t value;
- int length;
+ unsigned length;
inline ImmI8Operand(Decoder* decoder, const byte* pc) {
value = bit_cast<int8_t>(decoder->checked_read_u8(pc, 1, "immi8"));
length = 1;
@@ -44,7 +44,7 @@ struct ImmI8Operand {
struct ImmI32Operand {
int32_t value;
- int length;
+ unsigned length;
inline ImmI32Operand(Decoder* decoder, const byte* pc) {
value = decoder->checked_read_i32v(pc, 1, &length, "immi32");
}
@@ -52,7 +52,7 @@ struct ImmI32Operand {
struct ImmI64Operand {
int64_t value;
- int length;
+ unsigned length;
inline ImmI64Operand(Decoder* decoder, const byte* pc) {
value = decoder->checked_read_i64v(pc, 1, &length, "immi64");
}
@@ -60,7 +60,7 @@ struct ImmI64Operand {
struct ImmF32Operand {
float value;
- int length;
+ unsigned length;
inline ImmF32Operand(Decoder* decoder, const byte* pc) {
value = bit_cast<float>(decoder->checked_read_u32(pc, 1, "immf32"));
length = 4;
@@ -69,7 +69,7 @@ struct ImmF32Operand {
struct ImmF64Operand {
double value;
- int length;
+ unsigned length;
inline ImmF64Operand(Decoder* decoder, const byte* pc) {
value = bit_cast<double>(decoder->checked_read_u64(pc, 1, "immf64"));
length = 8;
@@ -80,7 +80,7 @@ struct GlobalIndexOperand {
uint32_t index;
LocalType type;
MachineType machine_type;
- int length;
+ unsigned length;
inline GlobalIndexOperand(Decoder* decoder, const byte* pc) {
index = decoder->checked_read_u32v(pc, 1, &length, "global index");
@@ -94,10 +94,10 @@ struct BreakDepthOperand {
uint32_t arity;
uint32_t depth;
Control* target;
- int length;
+ unsigned length;
inline BreakDepthOperand(Decoder* decoder, const byte* pc) {
- int len1 = 0;
- int len2 = 0;
+ unsigned len1 = 0;
+ unsigned len2 = 0;
arity = decoder->checked_read_u32v(pc, 1, &len1, "argument count");
depth = decoder->checked_read_u32v(pc, 1 + len1, &len2, "break depth");
length = len1 + len2;
@@ -109,10 +109,10 @@ struct CallIndirectOperand {
uint32_t arity;
uint32_t index;
FunctionSig* sig;
- int length;
+ unsigned length;
inline CallIndirectOperand(Decoder* decoder, const byte* pc) {
- int len1 = 0;
- int len2 = 0;
+ unsigned len1 = 0;
+ unsigned len2 = 0;
arity = decoder->checked_read_u32v(pc, 1, &len1, "argument count");
index = decoder->checked_read_u32v(pc, 1 + len1, &len2, "signature index");
length = len1 + len2;
@@ -124,10 +124,10 @@ struct CallFunctionOperand {
uint32_t arity;
uint32_t index;
FunctionSig* sig;
- int length;
+ unsigned length;
inline CallFunctionOperand(Decoder* decoder, const byte* pc) {
- int len1 = 0;
- int len2 = 0;
+ unsigned len1 = 0;
+ unsigned len2 = 0;
arity = decoder->checked_read_u32v(pc, 1, &len1, "argument count");
index = decoder->checked_read_u32v(pc, 1 + len1, &len2, "function index");
length = len1 + len2;
@@ -139,10 +139,10 @@ struct CallImportOperand {
uint32_t arity;
uint32_t index;
FunctionSig* sig;
- int length;
+ unsigned length;
inline CallImportOperand(Decoder* decoder, const byte* pc) {
- int len1 = 0;
- int len2 = 0;
+ unsigned len1 = 0;
+ unsigned len2 = 0;
arity = decoder->checked_read_u32v(pc, 1, &len1, "argument count");
index = decoder->checked_read_u32v(pc, 1 + len1, &len2, "import index");
length = len1 + len2;
@@ -154,13 +154,17 @@ struct BranchTableOperand {
uint32_t arity;
uint32_t table_count;
const byte* table;
- int length;
+ unsigned length;
inline BranchTableOperand(Decoder* decoder, const byte* pc) {
- int len1 = 0;
- int len2 = 0;
+ unsigned len1 = 0;
+ unsigned len2 = 0;
arity = decoder->checked_read_u32v(pc, 1, &len1, "argument count");
table_count =
decoder->checked_read_u32v(pc, 1 + len1, &len2, "table count");
+ if (table_count > (UINT_MAX / sizeof(uint32_t)) - 1 ||
+ len1 + len2 > UINT_MAX - (table_count + 1) * sizeof(uint32_t)) {
+ decoder->error(pc, "branch table size overflow");
+ }
length = len1 + len2 + (table_count + 1) * sizeof(uint32_t);
uint32_t table_start = 1 + len1 + len2;
@@ -171,8 +175,8 @@ struct BranchTableOperand {
table = nullptr;
}
}
- inline uint32_t read_entry(Decoder* decoder, int i) {
- DCHECK(i >= 0 && static_cast<uint32_t>(i) <= table_count);
+ inline uint32_t read_entry(Decoder* decoder, unsigned i) {
+ DCHECK(i <= table_count);
return table ? decoder->read_u32(table + i * sizeof(uint32_t)) : 0;
}
};
@@ -180,12 +184,12 @@ struct BranchTableOperand {
struct MemoryAccessOperand {
uint32_t alignment;
uint32_t offset;
- int length;
+ unsigned length;
inline MemoryAccessOperand(Decoder* decoder, const byte* pc) {
- int alignment_length;
+ unsigned alignment_length;
alignment =
decoder->checked_read_u32v(pc, 1, &alignment_length, "alignment");
- int offset_length;
+ unsigned offset_length;
offset = decoder->checked_read_u32v(pc, 1 + alignment_length,
&offset_length, "offset");
length = alignment_length + offset_length;
@@ -194,7 +198,7 @@ struct MemoryAccessOperand {
struct ReturnArityOperand {
uint32_t arity;
- int length;
+ unsigned length;
inline ReturnArityOperand(Decoder* decoder, const byte* pc) {
arity = decoder->checked_read_u32v(pc, 1, &length, "return count");
@@ -269,10 +273,10 @@ BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals,
const byte* start, const byte* end);
// Computes the length of the opcode at the given address.
-int OpcodeLength(const byte* pc, const byte* end);
+unsigned OpcodeLength(const byte* pc, const byte* end);
// Computes the arity (number of sub-nodes) of the opcode at the given address.
-int OpcodeArity(const byte* pc, const byte* end);
+unsigned OpcodeArity(const byte* pc, const byte* end);
} // namespace wasm
} // namespace internal
« no previous file with comments | « no previous file | src/wasm/ast-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698