Panic: unreachable!() in RealNumber::write when a CFF DICT real number overflows f32

Đang mở Phù hợp với người mới
#31 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
83/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu tại src/cff/number.rs, đọc RealNumber::parse và RealNumber::write; issue xác định thao tác phân tích cú pháp gây tràn số và đường dẫn gây panic. Tái hiện bằng phông chữ được cung cấp và xác nhận phông chữ chưa chỉnh sửa hoạt động thành công. Hoàn tất khi giá trị thực gây tràn số bị từ chối như một phông chữ không hợp lệ thay vì gây panic, kèm theo kiểm tra hồi quy cho hành vi đó.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

subset panics on a CFF font whose DICT holds a real number too large for f32, in debug and release builds alike:

thread 'main' panicked at subsetter-0.2.6/src/cff/number.rs:112:22:
internal error: entered unreachable code

RealNumber::parse parses the nibble string with str::parse::<f32>(), which returns inf for an exponent past the f32 range instead of failing. RealNumber::write then formats the value with format!("{}", self.0), gets "inf", and hits unreachable!() on the i. The backtrace goes through rewrite_top_dict_index (src/cff/dict/top_dict.rs:115), but any DICT that is written back with a real operand takes the same path.

To reproduce with subsetter 0.2.6 (default-features = false) and the font below (640 bytes, a minimal CFF OpenType font with two glyphs, where the first FontMatrix operand in the Top DICT is changed from 48828125E-11 to 48828125E99, i.e. the bytes 1e 48 82 81 25 c1 1f to 1e 48 82 81 25 b9 9f):

fn main() {
    let data = std::fs::read("cff-real-inf.otf").unwrap();
    let remapper = subsetter::GlyphRemapper::new();
    println!("{:?}", subsetter::subset(&data, 0, &remapper).map(|font| font.len()));
}

cargo run and cargo run --release both panic as above. The unmodified font prints Ok(476).

cff-real-inf.otf, base64 (decode with base64 -d > cff-real-inf.otf)
T1RUTwAJAIAAAwAQQ0ZGID2FLQsAAAIQAAAAZU9TLzJBOEHdAAABAAAAAGBjbWFwAAwAlAAAAbwA
AAA0aGVhZC9WaxIAAACcAAAANmhoZWEImgEuAAAA1AAAACRobXR4ArwAZAAAAngAAAAGbWF4cAAC
UAAAAAD4AAAABm5hbWU6H0HRAAABYAAAAFpwb3N0AAMAAAAAAfAAAAAgAAEAAAABAAD/pwTcXw88
9QADCAAAAAAA5vQRrwAAAADm9BGvAGQAAAH0ArwAAAADAAIAAAAAAAAAAQAABkD+cAAAAlgAZABk
AfQAAQAAAAAAAAAAAAAAAAAAAAEAAFAAAAIAAAADAlgBkAAFAAQAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAA/Pz8/AAAAQQBBAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAACAAAAAAAAQANgABAAAAAAABAAUAAAABAAAAAAACAAcABQADAAEECQABAAoADAADAAEE
CQACAA4AFlJlcHJvUmVndWxhcgBSAGUAcAByAG8AUgBlAGcAdQBsAGEAcgAAAAAAAgAAAAMAAAAU
AAMAAQAAABQABAAgAAAABAAEAAEAAABB//8AAABB////wAABAAAAAAADAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAQAEAQABAQEGUmVwcm8AAQEBJvgbAh5IgoEluZ+Lix5IgoElwR+LiwwH
74v4iPlQBc8Pi/AS0hEAAQEBBlJlcHJvAAAAACIAAgEBDRn47O8W+CT5UPwkBg747O8W+CT5UPwk
Bg4AAAACWABkAGQAAA==

SHA-256: 5c4f925da37caa1009b87e42eaa5410b59a69f386b617825f77c0339adc7ed6f

Returning None from RealNumber::parse when the parsed value is not finite would make this a MalformedFont error; a finite f32 always formats with {} as digits, . and - only, so write would then be safe. Found by fuzzing subsetter through the font registration of inkoxide; until it is fixed we check the DICT reals ourselves before calling subset.

Ngôn ngữ chính
Rust
Star
61
Fork
16
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của typst/subsetter

Tất cả issue của typst/subsetter

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.