Closed Bug 407415 Opened 17 years ago Closed 13 years ago

NaNs in gfx*Font with font-size:0 and font-size-adjust

Categories

(Core :: Graphics, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9

People

(Reporter: karlt, Assigned: karlt)

References

Details

(Whiteboard: [not needed for 1.9])

Attachments

(3 files)

Bug 407352 will hopefully mean this code path is not hit for this case, but let's protect anyway.
Attachment #292139 - Flags: review?(roc)
(In reply to comment #2)
> Do we have the same problem on Windows/Mac?
> http://bonsai.mozilla.org/cvsblame.cgi?file=/mozilla/gfx/thebes/src/gfxWindowsFonts.cpp&rev=1.160&root=/cvsroot&mark=192-193,262,245-246,253#189

Not sure.  Can mMetrics->emHeight be zero here?
Does bug 404112 comment 37 indicate that this is usually non-zero even for zero-size fonts?

Even if it can be zero, I can't see any looping here that could risk being infinite.

But I hear Windows sometimes crashes on NaNs, so it might be good to ensure we don't divide 0 by 0.

> http://bonsai.mozilla.org/cvsblame.cgi?file=/mozilla/gfx/thebes/src/gfxAtsuiFonts.cpp&rev=1.76&root=/cvsroot&mark=130-131,168-169,171-172,175#112

Yes, same kind of thing as Pango with zeros in slightly different places.
(In reply to comment #3)
> Not sure.  Can mMetrics->emHeight be zero here?

In branch builds some (buggy?) fonts resulted in zero ascent and descent.
I haven't tested trunk with said fonts so I don't know if it still occurs.
Seems like a good idea to make the code robust against it, just in case...
See bug 279032 and dupes.  (roc@ suggests in 279032 comment 17 we should
return all-zero metrics in this case)

> Does bug 404112 comment 37 indicate that this is usually non-zero even for
> zero-size fonts?

Yes, all three platforms returns some fallback font it seems.
(Windows/Mac had small values which I'm guessing is the minimal size
for that font.)   We should probably return all-zero metrics on all
platforms for a zero size font, for consistency (filed bug 407765).

> Even if it can be zero, I can't see any looping here that could risk being
> infinite.

On second reading it looks ok to me too.
Comment on attachment 292139 [details] [diff] [review]
don't repeat on zero size [checked-in for Pango]

Requesting approval for 1.9.  There are currently no known bugs that this fixes, but this makes things safer wrt changes elsewhere in the code.
Attachment #292139 - Flags: approval1.9?
Attachment #292139 - Flags: approval1.9? → approval1.9+
Changing platform to All
OS: Linux → All
Summary: NaNs in gfxPangoFont::RealizeFont with font-size:0 and font-size-adjust → NaNs in gfx*Font with font-size:0 and font-size-adjust
Attachment #292139 - Attachment description: don't repeat on zero size → don't repeat on zero size [checked-in]
Check for zero xHeight in Windows and Atsui code to avoid divide by zero in GetAdjustedSize().

Also makes changes to Windows/Atsui/Pango to make it clearer that these are floats not integers.

I haven't tested Windows/Atsui but the changes are simple.
Attachment #293072 - Flags: review?(roc)
Comment on attachment 293072 [details] [diff] [review]
check for zero xHeight [checked-in for Atsui]


Should you also check that emHeight is nonzero in gfxWindowsFonts to ensure we don't divide by zero on it? I guess it should be equal to the requested font size which should be nonzero, but I'm not sure if we can guarantee that.

If you want to do that, you can add it to this patch or make a new patch.
Attachment #293072 - Flags: superreview+
Attachment #293072 - Flags: review?(roc)
Attachment #293072 - Flags: review+
(In reply to comment #8)
> Should you also check that emHeight is nonzero in gfxWindowsFonts to ensure we
> don't divide by zero on it?

I don't think we need to guarantee that emHeight is non-zero.
IIUC dividing a non-zero by zero is not such an issue now that we use floats rather than ints.

"aspect = mMetrics->xHeight / 0.0f" would be +/-inf depending on the sign of mMetrics->xHeight, which is now not going to be 0.0f.

"size*(sizeAdjust/aspect)" would then be +/-0.0f provided size and sizeAdjust are not +/-inf (or NaN).
Attachment #293072 - Flags: approval1.9?
Attachment #293072 - Flags: approval1.9? → approval1.9+
This seems to be turning all the windows unit test tinderboxen orange.
Comment on attachment 293072 [details] [diff] [review]
check for zero xHeight [checked-in for Atsui]


This was checked in, then in gfxWindowsFont 0.0f was changed to 0.0 and the xHeight test was backed out as the MozillaAliveTest failed.

The 0.0f to 0.0 change was because I saw that gfxFloat is a double not a float.  This should probably be changed for Pango and Atsui too.

I suspect the MozillaAliveTest failed because mMetrics was null.  ("exited with status 5" is the only info I have.)  I haven't yet worked out the logic behind when to throw out the metrics,

http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/gfx/thebes/src/gfxWindowsFonts.cpp&rev=1.160&mark=252-253,257-259#245

so I'm not sure of the right way to avoid a 0.0/0.0.  But this is not a top priority right now.
Attachment #293072 - Attachment description: check for zero xHeight → check for zero xHeight [checked-in for Atsui]
Attachment #292139 - Attachment description: don't repeat on zero size [checked-in] → don't repeat on zero size [checked-in for Pango]
Comment on attachment 293072 [details] [diff] [review]
check for zero xHeight [checked-in for Atsui]


Looks like we don't want to land this.
Attachment #293072 - Flags: approval1.9+
Whiteboard: [not needed for 1.9]
So what should we do here?
I'd guess the analysis in this bug is out of date and so there's not much point keeping it open.  Marking fixed because something landed for Pango fonts.
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
OS: All → Linux
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: