Fix unwrap panic in extract_number_for_key in impl TraitAccessorPrivate for CTFontTraits on macOS Ventura. (#735)

* fix ventura crash

* formatting

---------

Co-authored-by: alokedesai <aloke@warp.dev>
This commit is contained in:
David Stern
2025-07-13 02:28:35 -04:00
committed by GitHub
parent 13cd1142e5
commit 0bcad1e103
+18 -1
View File
@@ -19,6 +19,7 @@ use core_foundation::url::{CFURLRef, CFURL};
use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType};
use core_graphics::base::CGFloat;
use core_foundation::boolean::CFBoolean;
use std::path::PathBuf;
/*
@@ -144,7 +145,23 @@ trait TraitAccessorPrivate {
impl TraitAccessorPrivate for CTFontTraits {
fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber {
let cftype = self.get(key);
cftype.downcast::<CFNumber>().unwrap()
let number = cftype.downcast::<CFNumber>();
match number {
Some(number) => number,
None => {
// The value was not able to be converted to a CFNumber, this violates the Core
// Foundation's docs (see https://developer.apple.com/documentation/coretext/kctfontsymbolictrait)
// but can occur in practice with certain fonts in MacOS 13 (Ventura). When this
// does occur in Ventura, the value returned is always a CFBoolean, so we attempt to
// convert into a boolean and create a number from there.
let value_as_bool = bool::from(
cftype
.downcast::<CFBoolean>()
.expect("Should be able to convert value into CFBoolean"),
);
CFNumber::from(value_as_bool as i32)
}
}
}
}