data URIs are not handled correctly by fetch()

RESOLVED FIXED in Firefox 43

Status

()

Core
DOM: Service Workers
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: seth, Assigned: nsm)

Tracking

unspecified
mozilla43
Points:
---
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(firefox39 affected, firefox40 affected, firefox41 affected, firefox42 affected, firefox43 fixed)

Details

MozReview Requests

()

Submitter Diff Changes Open Issues Last Updated
Loading...
Error loading review requests:

Attachments

(1 attachment)

(Reporter)

Description

2 years ago
There appears to be a bug in the implementation of fetch for data URIs. I discovered it when trying to fix a bug in test_fetch_event.html. If I replace the code for "nonexistent_image.gif" with this:

> else if (ev.request.url.includes("nonexistent_image.gif")) {
>   ev.respondWith(
>     fetch(new Request("data:image/gif;base64,R0lGODlhAQABAPAAAP8AAAAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw%3D%3D")));
> }

Then the test fails. Logging the response body from ImageLib, I see that we're just getting "R0lGODlhAQABAP..." as the response body - in other words, the data URI's data is not being properly decoded.

It looks to me like the problem lies here:

https://dxr.mozilla.org/mozilla-central/source/dom/fetch/FetchDriver.cpp#284

I think this code is assuming that nsDataHandler::ParseURI decoded |dataBuffer|, but it looks like ParseURI doesn't do that - it just splits the data URI into parts. We probably need to apply base64 decoding (and possibly URI decoding) manually.
(Reporter)

Updated

2 years ago
Flags: needinfo?(nsm.nikhil)

Comment 1

2 years ago
We shipped fetch in 39, so this is probably an issue as far back as that.
status-firefox39: --- → affected
status-firefox40: --- → affected
status-firefox41: --- → affected
status-firefox42: --- → affected
status-firefox43: --- → affected
Assignee: nobody → nsm.nikhil
Flags: needinfo?(nsm.nikhil)
Created attachment 8647703 [details]
MozReview Request: Bug 1193128 - Fix base64 decoding when fetching data URIs. r?baku

Bug 1193128 - Fix base64 decoding when fetching data URIs. r?baku
Attachment #8647703 - Flags: review?(amarchesini)
Comment on attachment 8647703 [details]
MozReview Request: Bug 1193128 - Fix base64 decoding when fetching data URIs. r?baku

https://reviewboard.mozilla.org/r/16035/#review15113

Ship It!

::: dom/fetch/FetchDriver.cpp:284
(Diff revision 1)
> +      if (NS_SUCCEEDED(channel->GetContentType(contentType))) {

would be nice to have a:

NS_WARN_IF_NOT(...)
Attachment #8647703 - Flags: review?(amarchesini) → review+
url:        https://hg.mozilla.org/integration/mozilla-inbound/rev/4d96f2d4807728039747d701d766b67108d96968
changeset:  4d96f2d4807728039747d701d766b67108d96968
user:       Nikhil Marathe <nsm.nikhil@gmail.com>
date:       Thu Aug 13 13:08:43 2015 -0700
description:
Bug 1193128 - Fix base64 decoding when fetching data URIs. r=baku
https://treeherder.mozilla.org/#/jobs?repo=try&revision=e8c021affdcc
url:        https://hg.mozilla.org/integration/mozilla-inbound/rev/af97951b7f1d68fd60255dc5211206b66a3d0676
changeset:  af97951b7f1d68fd60255dc5211206b66a3d0676
user:       Nikhil Marathe <nsm.nikhil@gmail.com>
date:       Thu Aug 13 13:08:43 2015 -0700
description:
Bug 1193128 - Fix base64 decoding when fetching data URIs. r=baku
https://hg.mozilla.org/mozilla-central/rev/af97951b7f1d
Status: NEW → RESOLVED
Last Resolved: 2 years ago
status-firefox43: affected → fixed
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla43
You need to log in before you can comment on or make changes to this bug.