Repository navigation
color: Normalize a non-finite hue to 0 degrees. - #461
BartWaardenburg wants to merge 1 commit into
Conversation
A hue that overflows f32, such as hsl(1e40 50% 50%), made normalize_hue return NaN. The NaN hue failed the debug assertion in hsl_to_rgb and gave wrong channels in a release build. CSS Color 4 says that an infinite hue normalizes to 0 degrees, and CSS Values 4 censors NaN to 0.
|
Do you mind contributing this directly upstream to Gecko? This is a downstream version of Stylo that regularly syncs with upstream. If you submit your change there, then it will soon make it's way here as well. |
|
Thanks for looking at this, @mrobinson, and for the pointer to the Gecko docs. I want to make sure I send it to the right place, so I tried to find this code in Gecko first. I may be missing something, but I could not find it there:
Is I also noticed that Stylo in Gecko has the same |
|
Ah, apologies. I thought this was the |
| ("hwb(1e40 0% 0%)", "hwb(0 0% 0%)"), | ||
| ("hwb(-1e40 0% 0%)", "hwb(0 0% 0%)"), | ||
| ("lch(50% 30 1e40)", "lch(50% 30 0)"), | ||
| ("oklch(50% 0.1 -1e40)", "oklch(50% 0.1 0)"), |
There was a problem hiding this comment.
As far as I know, the same issue exists in Firefox as well. So it would be great if you could submit a WPT test—that way, all browsers would benefit.
|
Thanks for the suggestion, @yisibl. Before I add a test, I want to check one thing with you. WPT already tests For a literal like Would a test with a value beyond every engine's range, such as |
Fixes #460.
A hue that overflows
f32, such ashsl(1e40 50% 50%), madenormalize_huereturn NaN. The NaN hue failed the debug assertion inhsl_to_rgb. In a release build,hsl(1e40 50% 50%)serialized asrgb(64, 64, 64).This change makes
normalize_huereturn 0 for an infinite or NaN hue. This follows the spec:The fix also covers
lch()andoklch(), which use the same function. Before,lch(50% 30 1e40)serialized aslch(50 30 calc(NaN)). Now it serializes aslch(50 30 0).Tests:
normalize_non_finite_huecovers1e40and-1e40inhsl(),hwb(),lch()andoklch(). It also covers angle units that overflow, such as1e38turn.normalize_finite_huechecks that finite hues outside [0, 360) still wrap as before.The new non-finite test fails on
mainin debug and release builds.cargo test -p cssparser-colorpasses with this change, in debug and release builds.Found by fuzzing Fallow (https://github.com/fallow-rs/fallow) with OSS-Fuzz.
Thanks for maintaining this crate.