cssparser-color: debug assertion in hsl_to_rgb for a hue that overflows f32
評估
研究方向
從 color/lib.rs 中的 normalize_hue 和第 307 行回報的斷言開始,接著檢查 hsl、hwb 和 lch 色彩轉換的測試。在 debug 建置中使用列出的溢位 hue 輸入重現問題,並將輸出與此處描述的 CSS Color 4 和 CSS Values 4 行為進行比較。當這些輸入不再觸發 panic,且產生指定結果時,即完成。
由索引模型根據 Issue 內容生成。
描述
A hue that overflows f32 makes normalize_hue return NaN. Examples are hwb(1e40 0% 0%) and hsl(1e40 50% 50%). In a debug build, to_css_string() on the parsed color then panics:
panicked at color/lib.rs:307:5:
assertion failed: (0.0..=1.0).contains(&hue)
hwb(1e30 0% 0%) does not panic, because 1e30 still fits in an f32.
normalize_hue computes hue - 360.0 * (hue / 360.0).floor(). For an infinite hue, this is inf - inf, which is NaN. A release build does not panic, but the output is wrong:
| Input | Release output |
|---|---|
hwb(1e40 0% 0%) |
rgb(0, 0, 0) |
hsl(1e40 50% 50%) |
rgb(64, 64, 64) |
lch(50% 30 1e40) |
lch(50 30 calc(NaN)) |
The spec gives the expected result. CSS Color 4 says that hsl(calc(infinity) 0 0) and hsl(calc(-infinity) 0 0) normalize the hue to 0 degrees. CSS Values 4 censors NaN to 0. So hwb(1e40 0% 0%) must give rgb(255, 0, 0).
Reproduced on main at 9f3cedd.
Related: #167 is about non-finite numbers from the tokenizer in general.
Found by fuzzing Fallow (https://github.com/fallow-rs/fallow) with OSS-Fuzz.
- 主要語言
- Rust
- 星號
- 874
- 分支
- 150
- 平均合併
- 9 分鐘
- 30 天內合併 PR
- 1
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
servo/rust-cssparser 的其他 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 85/100
servo/rust-cssparser#459 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 88/100
servo/rust-cssparser#440 ·
-
難度 2/5 1-3 小時 新手友好度 85/100
servo/rust-cssparser#439 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 84/100
servo/rust-cssparser#434 ·
-
難度 4/5 3-5 天 新手友好度 45/100
servo/rust-cssparser#438 · 3 則留言 · 1 個 reaction ·
查看 servo/rust-cssparser 的全部 Issue
相似的 Issue
-
checkpoint/verify/rebuild_indexes on a thread holding a WriteTransaction deadlock instead of INT-001未關閉bug known-issue
難度 2/5 1-3 小時 新手友好度 74/100
project-minigraf/minigraf#734 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 70/100
-
難度 1/5 1 小時以內 新手友好度 88/100
維護者通常 4 天內回覆
-
難度 2/5 1-3 小時 新手友好度 70/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 64/100
Nimblesite/lspkit#26 ·
維護者通常 1 天內回覆