Closed Bug 1193128 Opened 9 years ago Closed 9 years ago

data URIs are not handled correctly by fetch()

Categories

(Core :: DOM: Service Workers, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla43
Tracking Status
firefox39 --- affected
firefox40 --- affected
firefox41 --- affected
firefox42 --- affected
firefox43 --- fixed

People

(Reporter: seth, Assigned: nsm)

Details

Attachments

(1 file)

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.
Flags: needinfo?(nsm.nikhil)
We shipped fetch in 39, so this is probably an issue as far back as that.
Assignee: nobody → nsm.nikhil
Flags: needinfo?(nsm.nikhil)
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
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
Closed: 9 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla43
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: