|
|
|
@ -683,3 +683,73 @@ func TestUnmarshal(t *testing.T) { |
|
|
|
|
t.Fatal("expected error:", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestOOMMaliciousInput(t *testing.T) { |
|
|
|
|
oomTests := []unpackTest{ |
|
|
|
|
{ |
|
|
|
|
def: `[{"type": "uint8[]"}]`, |
|
|
|
|
enc: "0000000000000000000000000000000000000000000000000000000000000020" + // offset
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000003" + // num elems
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000001" + // elem 1
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000002", // elem 2
|
|
|
|
|
}, |
|
|
|
|
{ // Length larger than 64 bits
|
|
|
|
|
def: `[{"type": "uint8[]"}]`, |
|
|
|
|
enc: "0000000000000000000000000000000000000000000000000000000000000020" + // offset
|
|
|
|
|
"00ffffffffffffffffffffffffffffffffffffffffffffff0000000000000002" + // num elems
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000001" + // elem 1
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000002", // elem 2
|
|
|
|
|
}, |
|
|
|
|
{ // Offset very large (over 64 bits)
|
|
|
|
|
def: `[{"type": "uint8[]"}]`, |
|
|
|
|
enc: "00ffffffffffffffffffffffffffffffffffffffffffffff0000000000000020" + // offset
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000002" + // num elems
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000001" + // elem 1
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000002", // elem 2
|
|
|
|
|
}, |
|
|
|
|
{ // Offset very large (below 64 bits)
|
|
|
|
|
def: `[{"type": "uint8[]"}]`, |
|
|
|
|
enc: "0000000000000000000000000000000000000000000000007ffffffffff00020" + // offset
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000002" + // num elems
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000001" + // elem 1
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000002", // elem 2
|
|
|
|
|
}, |
|
|
|
|
{ // Offset negative (as 64 bit)
|
|
|
|
|
def: `[{"type": "uint8[]"}]`, |
|
|
|
|
enc: "000000000000000000000000000000000000000000000000f000000000000020" + // offset
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000002" + // num elems
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000001" + // elem 1
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000002", // elem 2
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
{ // Negative length
|
|
|
|
|
def: `[{"type": "uint8[]"}]`, |
|
|
|
|
enc: "0000000000000000000000000000000000000000000000000000000000000020" + // offset
|
|
|
|
|
"000000000000000000000000000000000000000000000000f000000000000002" + // num elems
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000001" + // elem 1
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000002", // elem 2
|
|
|
|
|
}, |
|
|
|
|
{ // Very large length
|
|
|
|
|
def: `[{"type": "uint8[]"}]`, |
|
|
|
|
enc: "0000000000000000000000000000000000000000000000000000000000000020" + // offset
|
|
|
|
|
"0000000000000000000000000000000000000000000000007fffffffff000002" + // num elems
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000001" + // elem 1
|
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000002", // elem 2
|
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
for i, test := range oomTests { |
|
|
|
|
def := fmt.Sprintf(`[{ "name" : "method", "outputs": %s}]`, test.def) |
|
|
|
|
abi, err := JSON(strings.NewReader(def)) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("invalid ABI definition %s: %v", def, err) |
|
|
|
|
} |
|
|
|
|
encb, err := hex.DecodeString(test.enc) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("invalid hex: %s" + test.enc) |
|
|
|
|
} |
|
|
|
|
_, err = abi.Methods["method"].Outputs.UnpackValues(encb) |
|
|
|
|
if err == nil { |
|
|
|
|
t.Fatalf("Expected error on malicious input, test %d", i) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|