Commit f7d28ab0 authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

[FileAPI] Fix CHECK failure if renderer sends zero-sized bytes element.

Bug: 1114898
Change-Id: I0b527a8fdc2dd4d5fcb5b9eb7140fa8ac4faa069
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2347921
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796935}
parent f79ec702
...@@ -372,8 +372,10 @@ void BlobRegistryImpl::BlobUnderConstruction::ResolvedAllBlobDependencies() { ...@@ -372,8 +372,10 @@ void BlobRegistryImpl::BlobUnderConstruction::ResolvedAllBlobDependencies() {
for (const auto& entry : elements_) { for (const auto& entry : elements_) {
auto& element = entry.element; auto& element = entry.element;
if (element->is_bytes()) { if (element->is_bytes()) {
transport_strategy_->AddBytesElement(element->get_bytes().get(), if (element->get_bytes()->length > 0) {
entry.bytes_provider); transport_strategy_->AddBytesElement(element->get_bytes().get(),
entry.bytes_provider);
}
} else if (element->is_file()) { } else if (element->is_file()) {
const auto& f = element->get_file(); const auto& f = element->get_file();
builder_->AppendFile( builder_->AppendFile(
......
...@@ -294,6 +294,37 @@ TEST_F(BlobRegistryImplTest, Register_EmptyBlob) { ...@@ -294,6 +294,37 @@ TEST_F(BlobRegistryImplTest, Register_EmptyBlob) {
EXPECT_EQ(0u, BlobsUnderConstruction()); EXPECT_EQ(0u, BlobsUnderConstruction());
} }
TEST_F(BlobRegistryImplTest, Register_EmptyBytesBlob) {
const std::string kId = "id";
const std::string kContentType = "content/type";
const std::string kContentDisposition = "disposition";
std::vector<blink::mojom::DataElementPtr> elements;
elements.push_back(
blink::mojom::DataElement::NewBytes(blink::mojom::DataElementBytes::New(
0, base::nullopt, CreateBytesProvider(""))));
mojo::Remote<blink::mojom::Blob> blob;
EXPECT_TRUE(registry_->Register(blob.BindNewPipeAndPassReceiver(), kId,
kContentType, kContentDisposition,
std::move(elements)));
EXPECT_TRUE(bad_messages_.empty());
EXPECT_EQ(kId, UUIDFromBlob(blob.get()));
EXPECT_TRUE(context_->registry().HasEntry(kId));
std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId);
EXPECT_EQ(kContentType, handle->content_type());
EXPECT_EQ(kContentDisposition, handle->content_disposition());
EXPECT_EQ(0u, handle->size());
WaitForBlobCompletion(handle.get());
EXPECT_FALSE(handle->IsBroken());
EXPECT_EQ(BlobStatus::DONE, handle->GetBlobStatus());
EXPECT_EQ(0u, BlobsUnderConstruction());
}
TEST_F(BlobRegistryImplTest, Register_ReferencedBlobClosedPipe) { TEST_F(BlobRegistryImplTest, Register_ReferencedBlobClosedPipe) {
const std::string kId = "id"; const std::string kId = "id";
......
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