Panic: debug_assert in SubroutineCollection::new on a CID-keyed font with 256 Font DICTs
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
- 74/100
Hướng nghiên cứu
Bắt đầu với subsetter-0.2.6/src/cff/subroutines.rs, đặc biệt là SubroutineCollection::new và đường đi get_handler, sau đó lần theo cách số lượng FDArray được biểu diễn. Chạy reproducer được cung cấp hoặc thêm một bài kiểm thử hồi quy cho 256 Font DICT. Công việc được xem là hoàn tất khi một phông chữ hợp lệ có 256 Font DICT không còn gây panic trong các bản dựng debug, và các số lượng không được hỗ trợ được xử lý mà không panic.
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 CID-keyed CFF font with 256 Font DICTs, in any build with debug assertions (debug builds, cargo test, fuzzing):
thread 'main' panicked at subsetter-0.2.6/src/cff/subroutines.rs:11:9:
assertion failed: subroutines.len() <= 255
SubroutineCollection::new asserts that there are at most 255 local subroutine lists, one per Font DICT. FDSelect gives each glyph's Font DICT as a Card8 (Technical Note #5176, FDSelect formats 0 and 3), so indices 0 to 255 address 256 Font DICTs, and a font with 256 is well formed. Without debug assertions subset returns Ok. This happens with 0.2.6 and with main (b0adcc1).
To reproduce with subsetter 0.2.6 (default-features = false). The font is built in code for this report:
/// A CFF INDEX of `items`.
fn index(items: &[Vec<u8>]) -> Vec<u8> {
if items.is_empty() {
return vec![0, 0];
}
let mut offsets = vec![1u32];
for item in items {
offsets.push(offsets.last().unwrap() + item.len() as u32);
}
let size = (1..=4u8).find(|&size| *offsets.last().unwrap() < 1 << (8 * size as u32)).unwrap();
let mut out = (items.len() as u16).to_be_bytes().to_vec();
out.push(size);
for offset in offsets {
out.extend(&offset.to_be_bytes()[4 - size as usize..]);
}
items.iter().for_each(|item| out.extend(item));
out
}
/// A DICT integer operand in five bytes.
fn int5(value: i32) -> Vec<u8> {
[&[29u8][..], &value.to_be_bytes()].concat()
}
/// A minimal OpenType font whose CFF table is CID-keyed: one glyph (.notdef, endchar)
/// and an FDArray of `count` Font DICTs, all pointing at one empty Private DICT. FDSelect
/// (format 0) puts the glyph in Font DICT 0.
fn font(count: usize) -> Vec<u8> {
let header = vec![1, 0, 4, 1];
let names = index(&[b"A".to_vec()]);
let strings = index(&[b"Adobe".to_vec(), b"Identity".to_vec()]);
let gsubrs = index(&[]);
let charstrings = index(&[vec![14]]);
let fdselect = vec![0, 0];
let top = |charstrings_at: i32, fdarray_at: i32, fdselect_at: i32| {
[
int5(391), int5(392), int5(0), vec![12, 30], // ROS Adobe-Identity-0
int5(charstrings_at), vec![17],
int5(fdarray_at), vec![12, 36],
int5(fdselect_at), vec![12, 37],
]
.concat()
};
let font_dict = |private_at: i32| [int5(0), int5(private_at), vec![18]].concat();
let top_len = index(&[top(0, 0, 0)]).len();
let fdarray_len = index(&vec![font_dict(0); count]).len();
let charstrings_at = header.len() + names.len() + top_len + strings.len() + gsubrs.len();
let fdselect_at = charstrings_at + charstrings.len();
let fdarray_at = fdselect_at + fdselect.len();
let private_at = fdarray_at + fdarray_len;
let top = index(&[top(charstrings_at as i32, fdarray_at as i32, fdselect_at as i32)]);
let fdarray = index(&vec![font_dict(private_at as i32); count]);
let cff = [header, names, top, strings, gsubrs, charstrings, fdselect, fdarray].concat();
let mut font = b"OTTO".to_vec();
for value in [1u16, 16, 0, 0] {
font.extend(value.to_be_bytes());
}
font.extend(b"CFF ");
for value in [0u32, 28, cff.len() as u32] {
font.extend(value.to_be_bytes());
}
font.extend(cff);
font
}
fn main() {
for count in [255, 256] {
let data = font(count);
let remapper = subsetter::GlyphRemapper::new();
println!("{count} Font DICTs: {:?}", subsetter::subset(&data, 0, &remapper).map(|font| font.len()));
}
}
cargo run prints 255 Font DICTs: Ok(156) and then panics as above; cargo run --release prints Ok(156) for both.
It was found while reviewing how officewright guards against subsetter panics; until it is fixed, our call to subset turns the panic into an error.
A possible fix: assert subroutines.len() <= 256, or, since get_handler takes a u8, return a CFFError for an FDArray of more than 256 Font DICTs instead of asserting.
- 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
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của typst/subsetter
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
head table bounding box is not recalculated for variable font instancesCó thể đã có người làm @khaledhosny đã nhận 16 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 56/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 45/100
-
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 67/100
Tất cả issue của typst/subsetter
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Input: placeholder drawn in the text colour when the empty Input is focused but not yet editedĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pierreaubert/gpui-toolkit#114 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
BibLaTeX `type` keys like `phdthesis`, `mathesis`, `techreport` are printed raw instead of localizedĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
remove the use of `forget`Đang mởgood first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 1 ngày
-
compiler
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
HerringtonDarkholme/hd-lang#1853 ·
Maintainer thường phản hồi trong vòng 1 ngày