Closed Bug 1019551 Opened 10 years ago Closed 6 years ago

Print preview fails if there's a 0-sized <canvas> element, due to failure case in CanvasRenderingContext2D::DrawImage()

Categories

(Core :: Printing: Output, defect)

19 Branch
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla59
Tracking Status
firefox-esr52 --- wontfix
firefox58 --- wontfix
firefox59 --- fixed

People

(Reporter: tomasz_smykowski, Assigned: jwatt)

References

(Blocks 1 open bug)

Details

(Keywords: regression)

Attachments

(6 files)

Attached file Desktop.rar
User Agent: Mozilla/5.0 (Windows NT 6.1; rv:29.0) Gecko/20100101 Firefox/29.0 (Beta/Release)
Build ID: 20140506152807

Steps to reproduce:

1. Open the html file attached.
2. Open Print Preview
3. Print preview flashes and closes
4. No way to display it.


Actual results:

Print preview is not displaying


Expected results:

Print preview should be displayed
I got the "There was an unexpected problem while printing." message in Fx30.
Component: Untriaged → Printing: Output
Product: Firefox → Core
I can reproduce.  This happens because we fail at cloning one of the nodes. The node in particular is a canvas node, and we apparently fail because it's 0-sized.

Each of these reduced testcases will reproduce the bug for me:
  data:text/html,<canvas width="0">
  data:text/html,<canvas height="0">

32.0a1 (2014-05-29)
Mozilla/5.0 (X11; Linux x86_64; rv:32.0) Gecko/20100101 Firefox/32.0
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Windows 7 → All
Hardware: x86 → All
Summary: Print preview stopped working from yesterday → Print preview fails if there's a 0-sized <canvas> element
Version: 29 Branch → Trunk
Specifically, we fail here in CanvasRenderingContext2D::DrawImage():
{
> 3283   if (image.IsHTMLCanvasElement()) {
> 3284     HTMLCanvasElement* canvas = &image.GetAsHTMLCanvasElement();
> 3285     element = canvas;
> 3286     nsIntSize size = canvas->GetSize();
> 3287     if (size.width == 0 || size.height == 0) {
> 3288       error.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
> 3289       return;
> 3290     }
http://mxr.mozilla.org/mozilla-central/source/content/canvas/src/CanvasRenderingContext2D.cpp?rev=57b0932e2f06#3283

...and that error gets propagated all the way up to nsPrintEngine.cpp, which fails the print [preview] operation and spawns an error dialog.

This return case was added back in http://hg.mozilla.org/mozilla-central/rev/a8171812fe05#l5.3587 (when this code looked slightly different).

roc or Bas, do you remember why this is a NS_ERROR_DOM_INVALID_STATE_ERR?  (Perhaps we need to do something different when we're not actually drawing anything and/or when we're doing this as part of printing?)

I'll attach a backtrace for this line of code in a minute, FWIW.
Summary: Print preview fails if there's a 0-sized <canvas> element → Print preview fails if there's a 0-sized <canvas> element, due to failure case in CanvasRenderingContext2D::DrawImage()
Depends on: 651858
Attachment #8433691 - Attachment description: reduced testcase 1: zero-width canvas → reduced testcase 2: zero-width canvas
Attachment #8433695 - Attachment description: backgrace of error → backtrace of error
(Perhaps HTMLCanvasElement::CopyInnerTo should have a version of the 0-size check from DrawImage(), and return without doing anything if we're 0-sized? But if we can handle this elegantly in DrawImage, that'd probably be better.)
What can i do to help fix this issue? It one month now when it's not working. And i need to print some things
Regression range:
good=2012-11-14
bad=2012-11-15
http://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=dd68409d7810&tochange=a761bfc192b5

Suspected:
Nicholas Cameron — Bug 800556; remove nsIDOMCanvasRenderingContext2D; r=Ms2ger,sr=bz
Blocks: 800556
Flags: needinfo?(ncameron)
Keywords: regression
Version: Trunk → 19 Branch
This bug still presents in Firefox 46.0.1
Code causing problem is 

<div style="display: none;" ><canvas height="0" width="0"></canvas></div>

This is enough to make any page unprintable
Blocks: 1296262
Attached patch patchSplinter Review
Assignee: nobody → jwatt
Attachment #8943815 - Flags: review?(lsalzman)
Flags: needinfo?(ncameron)
Attachment #8943815 - Flags: review?(lsalzman) → review+
Pushed by jwatt@jwatt.org:
https://hg.mozilla.org/integration/mozilla-inbound/rev/d8431cf09d20
Fix failure to print when pages contain zero sized <canvas>. r=lsalzman
https://hg.mozilla.org/mozilla-central/rev/d8431cf09d20
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla59
QA Whiteboard: [good first verify]
I have reproduced this bug with Nightly 32.0a1 (2014-06-03) on Windows 10, 64 Bit!

This bug's fix is verified with latest Beta!

Build ID   : 20180128191456
User Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0
QA Whiteboard: [good first verify] → [good first verify] [bugday-20180124]
I have Reproduced this bug with Firefox Nightly 60.0a1 (2018-02-07) on Windows 7, (32bit) 

Steps to Reproduce: 
1)Downloaded the Desktop.rar attached file
2)Open the html file which is present in that Desktop.rar file
3)Click on File -> Print Preview 
4)Print preview Flashed and Opened in the separate tab.

Actual Results:
Print Preview is displayed.

This Bug is Verified with Latest Beta too. 

Status: Fixed & Verified

Firefoxversion:60.0a1
Build ID: 20180206100151
User Agent: Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0
OS: Windows_NT 6.1


[bugday-20180207]
(In reply to Mohammed Adam from comment #16)
> I have Reproduced this bug with Firefox Nightly 60.0a1 (2018-02-07) on
> Windows 7, (32bit) 

"Reproduced" would mean that the bug is still present (unfixed) in 60.0a1. Presumably you mean "tried to reproduce"?
(In reply to Jonathan Watt [:jwatt] (needinfo? me) from comment #17)
> (In reply to Mohammed Adam from comment #16)
> > I have Reproduced this bug with Firefox Nightly 60.0a1 (2018-02-07) on
> > Windows 7, (32bit) 
> 
> "Reproduced" would mean that the bug is still present (unfixed) in 60.0a1.
> Presumably you mean "tried to reproduce"?

Sorry, I have Tried to Reproduce & the bug is fixed in the latest Nightly and Beta version.
Awesome. Thanks for checking and confirming!
You need to log in before you can comment on or make changes to this bug.