Commit 510ff8e4 authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

Cancel multipart image parser when decoding failed

Before this CL we didn't stop appending data for mulitpart images
even after there was an decode error. This doesn't align the assumption
the base class has. The base class, Resource, doesn't expect calling
AppendData() when there was an error. We should cancel the parser when
there is a decode error so that we don't append data after the error.

Bug: 813485
Change-Id: I40112e11bf1d7d1c84e2794c81bbaf178207496f
Reviewed-on: https://chromium-review.googlesource.com/923668Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537689}
parent b9d99f5f
<!DOCTYPE html>
<title>Test for loading invalid multipart image</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script>
async_test(t => {
const img = document.createElement('img');
img.onload = t.step_func(() => {
assert_unreached('The image should not be loaded');
});
img.onerror = t.step_func_done((e) => {
assert_equals(e.type, 'error');
});
img.src = 'resources/invalid-multipart-image.php';
}, 'invalid multipart image should not be loaded');
</script>
<?php
$boundary = "cutHere";
function sendPart($data)
{
global $boundary;
echo("Content-Type: image/png\r\n\r\n");
echo($data);
echo("--$boundary\r\n");
flush();
}
header("Content-Type: multipart/x-mixed-replace; boundary=$boundary");
echo("--$boundary\r\n");
ob_end_flush();
$invalidImage = "Invalid PNG data";
sendPart($invalidImage);
$validImage = file_get_contents("2x2-green.png");
sendPart($validImage);
?>
...@@ -374,6 +374,9 @@ void ImageResource::DecodeError(bool all_data_received) { ...@@ -374,6 +374,9 @@ void ImageResource::DecodeError(bool all_data_received) {
if (!ErrorOccurred()) if (!ErrorOccurred())
SetStatus(ResourceStatus::kDecodeError); SetStatus(ResourceStatus::kDecodeError);
if (multipart_parser_)
multipart_parser_->Cancel();
bool is_multipart = !!multipart_parser_; bool is_multipart = !!multipart_parser_;
// Finishes loading if needed, and notifies observers. // Finishes loading if needed, and notifies observers.
if (!all_data_received && Loader()) { if (!all_data_received && Loader()) {
...@@ -405,7 +408,8 @@ void ImageResource::NotifyStartLoad() { ...@@ -405,7 +408,8 @@ void ImageResource::NotifyStartLoad() {
void ImageResource::Finish(double load_finish_time, void ImageResource::Finish(double load_finish_time,
base::SingleThreadTaskRunner* task_runner) { base::SingleThreadTaskRunner* task_runner) {
if (multipart_parser_) { if (multipart_parser_) {
multipart_parser_->Finish(); if (!ErrorOccurred())
multipart_parser_->Finish();
if (Data()) if (Data())
UpdateImageAndClearBuffer(); UpdateImageAndClearBuffer();
} else { } else {
......
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