font browser
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;