Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

cssparser-color: debug assertion in hsl_to_rgb for a hue that overflows f32

未關閉 適合新手
#460 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

@BartWaardenburg 已經在處理了。

開始於 2026年10月22日。

  • #461 來自 @BartWaardenburg —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
64/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
rust
領域
frontend, web-dev

研究方向

從 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,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

servo/rust-cssparser 的其他 Issue

查看 servo/rust-cssparser 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。