Commit 7c6ff8b1 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm] Fix heap type clusterfuzz issue

Also shuffle HeapType helper functionality a bit

Bug: chromium:1101629, v8:7748
Change-Id: I7c27dc96f02173c73dbac7b518e7936e4e0d5bf3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2275965Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68659}
parent a7115749
...@@ -163,8 +163,9 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc, ...@@ -163,8 +163,9 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc,
return result; return result;
} }
default: default:
if (validate) if (validate) {
decoder->errorf(pc, "Unknown heap type %" PRId64, heap_index); decoder->errorf(pc, "Unknown heap type %" PRId64, heap_index);
}
return HeapType(HeapType::kBottom); return HeapType(HeapType::kBottom);
} }
UNREACHABLE(); UNREACHABLE();
...@@ -1432,6 +1433,10 @@ class WasmDecoder : public Decoder { ...@@ -1432,6 +1433,10 @@ class WasmDecoder : public Decoder {
} }
inline bool Validate(const byte* pc, HeapTypeImmediate<validate>& imm) { inline bool Validate(const byte* pc, HeapTypeImmediate<validate>& imm) {
if (!VALIDATE(!imm.type.is_bottom())) {
error(pc, "invalid heap type");
return false;
}
if (!VALIDATE(imm.type.is_generic() || if (!VALIDATE(imm.type.is_generic() ||
module_->has_array(imm.type.ref_index()) || module_->has_array(imm.type.ref_index()) ||
module_->has_struct(imm.type.ref_index()))) { module_->has_struct(imm.type.ref_index()))) {
......
...@@ -78,7 +78,7 @@ class HeapType { ...@@ -78,7 +78,7 @@ class HeapType {
} }
explicit constexpr HeapType(Representation repr) : representation_(repr) { explicit constexpr HeapType(Representation repr) : representation_(repr) {
CONSTEXPR_DCHECK(is_valid()); CONSTEXPR_DCHECK(is_bottom() || is_valid());
} }
explicit constexpr HeapType(uint32_t repr) explicit constexpr HeapType(uint32_t repr)
: HeapType(static_cast<Representation>(repr)) {} : HeapType(static_cast<Representation>(repr)) {}
...@@ -97,10 +97,10 @@ class HeapType { ...@@ -97,10 +97,10 @@ class HeapType {
} }
constexpr bool is_generic() const { constexpr bool is_generic() const {
return representation_ >= kFirstSentinel; return !is_bottom() && representation_ >= kFirstSentinel;
} }
constexpr bool is_index() const { return !is_generic(); } constexpr bool is_index() const { return !is_bottom() && !is_generic(); }
constexpr bool is_bottom() const { return representation_ == kBottom; } constexpr bool is_bottom() const { return representation_ == kBottom; }
...@@ -144,7 +144,9 @@ class HeapType { ...@@ -144,7 +144,9 @@ class HeapType {
private: private:
friend class ValueType; friend class ValueType;
Representation representation_; Representation representation_;
constexpr bool is_valid() const { return representation_ <= kLastSentinel; } constexpr bool is_valid() const {
return !is_bottom() && representation_ <= kLastSentinel;
}
}; };
enum Nullability : bool { kNonNullable, kNullable }; enum Nullability : bool { kNonNullable, kNullable };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment