This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 15000 - Don't fire load until the image is fully decodable. If the image is corrupt or unsupported, the spec says to fire load *and* error, but browsers don't do that.
Summary: Don't fire load until the image is fully decodable. If the image is corrupt o...
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-30 09:15 UTC by contributor
Modified: 2012-09-15 02:10 UTC (History)
6 users (show)

See Also:


Attachments

Description contributor 2011-11-30 09:15:09 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-content-1.html
Multipage: http://www.whatwg.org/C#img-load
Complete: http://www.whatwg.org/c#img-load

Comment:
Don't fire load until the image is fully decodable. If the image is corrupt or
unsupported, the spec says to fire load *and* error, but browsers don't do
that.

Posted from: 85.227.157.105 by simonp@opera.com
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_8) AppleWebKit/535.8 (KHTML, like Gecko) Chrome/17.0.942.0 Safari/535.8
Comment 1 Simon Pieters 2011-11-30 10:03:01 UTC
Mistake, the spec doesn't say to fire both load and error. It says to fire load if the load was successful, without checking if the image is corrupt first.
Comment 2 Ian 'Hixie' Hickson 2012-01-31 21:00:50 UTC
I believe the spec matches reality here. Browsers fire 'load' before they inspect the data in some cases. Do you have a test case demonstrating otherwise?
Comment 3 Simon Pieters 2012-02-01 08:01:45 UTC
http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1318

The spec requires 'load' but Opera/Firefox/Chrome fire 'error'
Comment 4 contributor 2012-07-18 16:05:59 UTC
This bug was cloned to create bug 18039 as part of operation convergence.
Comment 5 Ian 'Hixie' Hickson 2012-07-27 02:13:31 UTC
Huh. bz, can you take a look at this and see if you have any insight? I think it was you who pointed out that in some cases you fire 'load' before you have deeply inspected the image data (but I could be wrong).
Comment 6 Boris Zbarsky 2012-07-27 02:26:11 UTC
I believe that Gecko will fire load or error after it has all the image data but possibly before it's decoded it all.  In particular, it will decode some amount of data (there's a data size below which the decode is sync), then do the rest of decode async and fire the load or error, depending on which one is relevant.

I'll double-check whether my believe is correct.
Comment 7 Boris Zbarsky 2012-07-27 02:28:18 UTC
And in particular, there are various cases in which I think Gecko suppresses decoding indefinitely (until something asks for the decoded data).  And more in which we would like to do so.  It would be pretty unfortunate if the spec precluded this.
Comment 8 Bobby Holley (:bholley) 2012-07-27 07:42:07 UTC
(In reply to comment #6)
> I believe that Gecko will fire load or error after it has all the image data
> but possibly before it's decoded it all.  In particular, it will decode some
> amount of data (there's a data size below which the decode is sync), then do
> the rest of decode async and fire the load or error, depending on which one is
> relevant.
> 
> I'll double-check whether my believe is correct.

Yes. The callback in which we fire onerror is unfortunately named OnStopDecode (jdm will fix this soon), but it's fired at the end of the load.

I investigated this behavior back when I was implementing decode-on-draw. Here's the relevant comment:

https://bugzilla.mozilla.org/show_bug.cgi?id=435296#c27

Here's the most relevant bit.

> If this instantiation fails, we fire "onerror". If it succeeds, we fire
> "onload". Thus, the only cases where we fire onerror are:
> 1) The URL is somehow invalid or ruffles the feathers of the content policy
> 2) A network error occurs before all the data arrives
> 3) The first few (sniffed) bytes give us an invalid mimetype, an we balk on
> decoder instantiation
>
> Otherwise, we fire onload once the network request completes. Furthermore, I
> did some testing and this exact behavior is replicated in safari and chrome
> (I don't have IE handy).


(In reply to comment #7)
> And in particular, there are various cases in which I think Gecko suppresses
> decoding indefinitely (until something asks for the decoded data).  And more in
> which we would like to do so.  It would be pretty unfortunate if the spec
> precluded this.

Indeed. It would kill decode-on-draw.
Comment 9 Ian 'Hixie' Hickson 2012-08-29 21:56:32 UTC
So, what do we want to do here? Fire 'load' for corrupt images, or fire both 'load' and 'error' for those images?
Comment 10 Ian 'Hixie' Hickson 2012-09-07 20:10:12 UTC
bz suggests that we should just fire onload once we have dimension metadata, and not ever fire onerror for corrupted image data. I'll move the spec to that.
Comment 11 L. David Baron (Mozilla) 2012-09-07 21:52:06 UTC
(In reply to comment #10)
> bz suggests that we should just fire onload once we have dimension metadata,

Presumably you mean "as long as you have dimension metadata", but once the image is fully loaded (corrupt or not)?
Comment 12 Ian 'Hixie' Hickson 2012-09-13 23:48:29 UTC
dbaron: As soon as all the bytes are retrieved and enough of the image has been decoded that you have image data, but not later (in particular, not requiring the pixel data itself to be decoded at all).
Comment 13 Simon Pieters 2012-09-14 07:50:28 UTC
I guess drawImage() needs to block waiting for the image to be decoded, right?
Comment 14 Bobby Holley (:bholley) 2012-09-14 10:36:05 UTC
(In reply to comment #13)
> I guess drawImage() needs to block waiting for the image to be decoded, right?

If you defer image decoding (an optimization that this spec change allows, but does not require), then yes. Mozilla has a "SyncDecode()" function on images that we use for drawImage and a few other miscellaneous cases.
Comment 15 Ian 'Hixie' Hickson 2012-09-15 02:09:59 UTC
This doesn't change drawImage() behaviour. It's needed to be able to do sync decode for a while.

Original bug is now fixed.
Comment 16 contributor 2012-09-15 02:10:04 UTC
Checked in as WHATWG revision r7349.
Check-in comment: Make onerror on <img> only fire when onload doesn't fire.
http://html5.org/tools/web-apps-tracker?from=7348&to=7349