Closed Bug 1497925 Opened Last year Closed Last year

createImageBitmap fails with particular content types


(Core :: DOM: Core & HTML, defect)

Not set



Tracking Status
firefox65 --- fixed


(Reporter: jaffathecake, Assigned: baku)



(1 file, 1 obsolete file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36

Steps to reproduce:

Some servers, such as Webpack's dev server, serve images with content types like 'image/png; charset=UTF-8'.

Firefox can display these images fine. However, createImageBitmap will blobs with types like this.


Actual results:

createImageBitmap rejects with "InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable"

Expected results:

The bitmap should have been created. View the demo in Chrome/Safari for the correct result.
"createImageBitmap will blobs with types like this" should be "createImageBitmap will *reject* blobs with types like this"
On the HTTP path, we properly parse the MIME type to extract the content type and the content charset, using:

It seems we are just passing it straight through on the createImageBitmap path. The blobs should probably be parsing the MIME type like the network?
Component: Canvas: 2D → DOM
Ever confirmed: true
Flags: needinfo?(amarchesini)
What you are proposing is against the current fetch spec. says:

"To extract a MIME type from a header list (headers), run these steps:
    Let mimeType be the result of extracting header list values given `Content-Type` and headers.
    If mimeType is null or failure, then return the empty byte sequence.
    Return mimeType, byte-lowercased."

The bug here is not in the blob.type, but in how we implement the CreateImageBitmap spec:

"Let imageData be the result of reading image's data. If an error occurs during reading of the object, then reject p with an \"InvalidStateError\" DOMException and abort these steps. Apply the image sniffing rules to determine the file format of imageData, with MIME type of image (as given by image's type attribute) giving the official type."

It seems that we should not relay on the blob type at all. But currently we use the type. The failure happens here:
Flags: needinfo?(amarchesini) → needinfo?(aosmond)
Attached patch image.patch (obsolete) — Splinter Review
Assignee: nobody → amarchesini
Flags: needinfo?(aosmond)
Attachment #9018790 - Flags: review?(aosmond)
Attached patch image.patchSplinter Review
Attachment #9018790 - Attachment is obsolete: true
Attachment #9018790 - Flags: review?(aosmond)
Attachment #9018953 - Flags: review?(aosmond)
Attachment #9018953 - Flags: review?(aosmond) → review+
Pushed by
CreateImageBitmap must ignore the Blob.type value, r=aosmond
Created web-platform-tests PR for changes under testing/web-platform/tests
Closed: Last year
Resolution: --- → FIXED
Target Milestone: --- → mozilla65
Upstream PR merged
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.