Commit e7a00891 authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] Fix decoder for null data

If passing <nullptr, 0> to the decoder and trying to decode something,
it correctly detects the error and sets an error message, but still
returns true on ok(), and returns a valid result.
I triggered this error by passing a null Vector, returned by FindSection(), to
the decoder.

R=titzer@chromium.org

Review-Url: https://codereview.chromium.org/2410913002
Cr-Commit-Position: refs/heads/master@{#40204}
parent 3d41efce
...@@ -253,7 +253,7 @@ class Decoder { ...@@ -253,7 +253,7 @@ class Decoder {
template <typename T> template <typename T>
Result<T> toResult(T val) { Result<T> toResult(T val) {
Result<T> result; Result<T> result;
if (error_pc_) { if (failed()) {
TRACE("Result error: %s\n", error_msg_.get()); TRACE("Result error: %s\n", error_msg_.get());
result.error_code = kError; result.error_code = kError;
result.start = start_; result.start = start_;
...@@ -279,8 +279,8 @@ class Decoder { ...@@ -279,8 +279,8 @@ class Decoder {
error_msg_.reset(); error_msg_.reset();
} }
bool ok() const { return error_pc_ == nullptr; } bool ok() const { return error_msg_ == nullptr; }
bool failed() const { return !!error_msg_; } bool failed() const { return !ok(); }
bool more() const { return pc_ < limit_; } bool more() const { return pc_ < limit_; }
const byte* start() { return start_; } const byte* start() { return start_; }
......
...@@ -671,6 +671,13 @@ TEST_F(DecoderTest, ReadI64v_extra_bits_positive) { ...@@ -671,6 +671,13 @@ TEST_F(DecoderTest, ReadI64v_extra_bits_positive) {
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} }
TEST_F(DecoderTest, FailOnNullData) {
decoder.Reset(nullptr, 0);
decoder.checkAvailable(1);
EXPECT_FALSE(decoder.ok());
EXPECT_FALSE(decoder.toResult(nullptr).ok());
}
} // namespace wasm } // namespace wasm
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
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