git.lucas.co / cce-fonts
font browser

commitf585ac463ad63373a9f5b45c69c7d69911ce0ea5
parent375a2aa938
authorLucas Galante <[email protected]>
date2026-07-07 21:08
fix: don't crash loading fonts with reversed fc-query charset ranges

count_chars parsed fc-query %{charset} ranges as start-end and did (end - start) on u32s; a font whose charset reports a reversed range underflowed and panicked the whole app on startup. Guard with end >= start.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

 src/pages.rs | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/pages.rs b/src/pages.rs
index 1bc69b8..c00e3cc 100644
--- a/src/pages.rs
+++ b/src/pages.rs
@@ -57,7 +57,11 @@ pub fn count_chars(file: &str) -> usize {
             for range in s.split_whitespace() {
                 if let Some((start, end)) = range.split_once('-') {
                     if let (Ok(s_val), Ok(e_val)) = (u32::from_str_radix(start, 16), u32::from_str_radix(end, 16)) {
-                        count += (e_val - s_val + 1) as usize;
+                        // Guard against malformed/reversed ranges (end < start) — an unsigned
+                        // subtraction there panics and crashes the whole app.
+                        if e_val >= s_val {
+                            count += (e_val - s_val + 1) as usize;
+                        }
                     }
                 } else if let Ok(_) = u32::from_str_radix(range, 16) {
                     count += 1;