Commit 9e7e457d authored by Kunihiko Sakamoto's avatar Kunihiko Sakamoto Committed by Commit Bot

Fix BundledExchangesParserFuzzer

This fixes a bug where set_disconnect_handler() was called on invalid
PendingReceiver. Now the parser is created using
BundledExchangesParserFactory.

TBR=rsesek@chromium.org

Bug: 984918,984950,984980,984991,985159,985191
Change-Id: I7d628a084291077186d42fa7191255429d9c190c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1707950
Commit-Queue: Kunihiko Sakamoto <ksakamoto@chromium.org>
Reviewed-by: default avatarTakashi Toyoshima <toyoshim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#678585}
parent e2253fae
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "mojo/core/embedder/embedder.h" #include "mojo/core/embedder/embedder.h"
#include "mojo/public/cpp/bindings/receiver_set.h" #include "mojo/public/cpp/bindings/receiver_set.h"
#include "services/data_decoder/bundled_exchanges_parser.h" #include "services/data_decoder/bundled_exchanges_parser.h"
#include "services/data_decoder/bundled_exchanges_parser_factory.h"
namespace { namespace {
...@@ -27,8 +28,10 @@ class DataSource : public data_decoder::mojom::BundleDataSource { ...@@ -27,8 +28,10 @@ class DataSource : public data_decoder::mojom::BundleDataSource {
} }
void Read(uint64_t offset, uint64_t length, ReadCallback callback) override { void Read(uint64_t offset, uint64_t length, ReadCallback callback) override {
if (offset + length > size_) if (offset + length > size_) {
std::move(callback).Run(base::nullopt); std::move(callback).Run(base::nullopt);
return;
}
const uint8_t* start = data_ + offset; const uint8_t* start = data_ + offset;
std::move(callback).Run(std::vector<uint8_t>(start, start + length)); std::move(callback).Run(std::vector<uint8_t>(start, start + length));
} }
...@@ -55,15 +58,14 @@ class BundledExchangesParserFuzzer { ...@@ -55,15 +58,14 @@ class BundledExchangesParserFuzzer {
data_source_.AddReceiver( data_source_.AddReceiver(
data_source_remote.InitWithNewPipeAndPassReceiver()); data_source_remote.InitWithNewPipeAndPassReceiver());
mojo::PendingRemote<data_decoder::mojom::BundledExchangesParser> data_decoder::BundledExchangesParserFactory factory_impl(
remote_parser; /*service_ref=*/nullptr);
std::unique_ptr<data_decoder::mojom::BundledExchangesParser> parser = data_decoder::mojom::BundledExchangesParserFactory& factory = factory_impl;
std::make_unique<data_decoder::BundledExchangesParser>( factory.GetParserForDataSource(parser_.BindNewPipeAndPassReceiver(),
remote_parser.InitWithNewPipeAndPassReceiver(), std::move(data_source_remote));
std::move(data_source_remote));
quit_loop_ = run_loop->QuitClosure(); quit_loop_ = run_loop->QuitClosure();
parser->ParseMetadata( parser_->ParseMetadata(
base::Bind(&BundledExchangesParserFuzzer::OnParseMetadata, base::Bind(&BundledExchangesParserFuzzer::OnParseMetadata,
base::Unretained(this))); base::Unretained(this)));
} }
...@@ -84,17 +86,7 @@ class BundledExchangesParserFuzzer { ...@@ -84,17 +86,7 @@ class BundledExchangesParserFuzzer {
return; return;
} }
mojo::PendingRemote<data_decoder::mojom::BundleDataSource> parser_->ParseResponse(
data_source_remote;
data_source_.AddReceiver(
data_source_remote.InitWithNewPipeAndPassReceiver());
mojo::PendingReceiver<data_decoder::mojom::BundledExchangesParser> receiver;
data_decoder::BundledExchangesParser parser_impl(
std::move(receiver), std::move(data_source_remote));
data_decoder::mojom::BundledExchangesParser& parser = parser_impl;
parser.ParseResponse(
metadata_->index[index]->response_offset, metadata_->index[index]->response_offset,
metadata_->index[index]->response_length, metadata_->index[index]->response_length,
base::Bind(&BundledExchangesParserFuzzer::OnParseResponse, base::Bind(&BundledExchangesParserFuzzer::OnParseResponse,
...@@ -108,6 +100,7 @@ class BundledExchangesParserFuzzer { ...@@ -108,6 +100,7 @@ class BundledExchangesParserFuzzer {
} }
private: private:
mojo::Remote<data_decoder::mojom::BundledExchangesParser> parser_;
DataSource data_source_; DataSource data_source_;
base::Closure quit_loop_; base::Closure quit_loop_;
data_decoder::mojom::BundleMetadataPtr metadata_; data_decoder::mojom::BundleMetadataPtr metadata_;
......
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