From a2f41d728e43d9ab183bfe129005630f4bfd5c57 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Mon, 16 Nov 2026 22:41:53 +0100 Subject: [PATCH] M14: distinguish font file and unpacked size limits in errors (#6719) --- crates/fonts/src/fontdb/user.rs | 8 +++++++- crates/fonts/src/fontdb/user/tests.rs | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/fonts/src/fontdb/user.rs b/crates/fonts/src/fontdb/user.rs index 03f449cdb7..b7aac73983 100644 --- a/crates/fonts/src/fontdb/user.rs +++ b/crates/fonts/src/fontdb/user.rs @@ -63,7 +63,13 @@ impl std::fmt::Display for UserFontError { match self { UserFontError::Empty => write!(f, "the font file is empty"), UserFontError::TooLarge { bytes } => { - write!(f, "the font file is too large ({} MB; at most {} MB)", bytes.div_ceil(1 << 20), MAX_FONT_FILE_BYTES >> 20) + write!( + f, + "the font is too large ({} MB; file limit {} MB, unpacked limit {} MB)", + bytes.div_ceil(1 << 20), + MAX_FONT_FILE_BYTES >> 20, + MAX_DECODED_BYTES >> 20 + ) } UserFontError::NotAFont => write!(f, "not a font file (TrueType, OpenType, TTC, WOFF or WOFF2)"), UserFontError::BadWebFont(e) => write!(f, "the web font couldn't be read: {e}"), diff --git a/crates/fonts/src/fontdb/user/tests.rs b/crates/fonts/src/fontdb/user/tests.rs index a8673e5a1e..f1a71ac985 100644 --- a/crates/fonts/src/fontdb/user/tests.rs +++ b/crates/fonts/src/fontdb/user/tests.rs @@ -210,7 +210,9 @@ fn woff1_claiming(orig: u32) -> Vec { fn a_woff_claiming_a_huge_table_is_refused_before_inflating() { // #3703: the decoder sizes a table's buffer from the directory before inflating it. for orig in [200 << 20, u32::MAX] { - assert!(matches!(decode_font_file(&woff1_claiming(orig)), Err(UserFontError::TooLarge { .. })), "{orig}"); + let error = decode_font_file(&woff1_claiming(orig)).unwrap_err(); + assert!(matches!(&error, UserFontError::TooLarge { .. }), "{orig}"); + assert!(error.to_string().contains("unpacked limit 128 MB"), "{error}"); } // A small claim reaches the decoder, which finds the data doesn't inflate to it. assert!(matches!(decode_font_file(&woff1_claiming(64)), Err(UserFontError::BadWebFont(_)))); @@ -311,7 +313,9 @@ fn junk_is_rejected_without_adding_anything() { assert_eq!(db.families().len(), n + db.user_fonts().iter().map(|u| u.families().len()).sum::()); let mut big = regular.clone(); big.resize(MAX_FONT_FILE_BYTES + 1, 0); - assert!(matches!(db.install_font("big.ttf", &big), Err(UserFontError::TooLarge { .. }))); + let error = db.install_font("big.ttf", &big).unwrap_err(); + assert!(matches!(&error, UserFontError::TooLarge { .. })); + assert!(error.to_string().contains("file limit 50 MB"), "{error}"); } #[test]