cmap format 4 drops glyph IDs above 32767 in the glyphIdArray path
还没有人认领这个 Issue。
- #248 来自 @msl2246 —— 已关闭,未合并
评估
调研方向
问题位于 src/tables/cmap/format4.rs 中 Format 4 的 glyphIdArray 分支,大约第 85–93 行。阅读零值条目检查和 idDelta 加法的实现方式,然后运行 issue 中的合成复现用例,确认对 0xE123 返回的是 None。完成的标准是:该测试返回 Some(GlyphId(0x8001)),tests/tables/cmap.rs 中现有的 cmap 测试全部通过,并在那里添加一个回归测试。
由索引模型根据 Issue 内容生成。
描述
Summary
In the Format 4 branch where idRangeOffset is nonzero, Subtable4::glyph_index casts the glyphIdArray entry to i16, adds idDelta, and tries to convert the signed result back to u16. When the correct result is above 32767, the signed intermediate is negative and the lookup returns None. As a result, text renderers can treat mapped characters as missing and use a fallback font. This can affect large CJK fonts.
The bug is present in the current release, 0.25.1, and in main at 0c7291223fe9e0bc2808f0255cb991066eedd796. Release v0.25.1 · Format 4 lookup on main
OpenType defines glyphIdArray entries as unsigned 16-bit values. A zero entry denotes a missing glyph. For a nonzero entry, the glyph ID is the entry plus idDelta modulo 65536. OpenType cmap specification, Format 4
Minimal reproduction
Add ttf-parser = "=0.25.1" under [dependencies] in a Rust library crate. Put this test in src/lib.rs and run cargo test. The entire subtable is synthetic and contains one mapping and the required sentinel.
#[test]
fn format4_indirect_lookup_preserves_high_glyph_ids() {
use ttf_parser::{cmap::Subtable4, GlyphId};
// Synthetic Format 4 subtable with one mapped code and a sentinel.
let data = [
0x00, 0x04, 0x00, 0x22, 0x00, 0x00, // format, length, language
0x00, 0x04, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, // search parameters
0xE1, 0x23, 0xFF, 0xFF, // endCode
0x00, 0x00, // reservedPad
0xE1, 0x23, 0xFF, 0xFF, // startCode
0x00, 0x00, 0x00, 0x01, // idDelta
0x00, 0x04, 0x00, 0x00, // idRangeOffset
0x80, 0x01, // glyphIdArray
];
let subtable = Subtable4::parse(&data).unwrap();
assert_eq!(subtable.glyph_index(0xE123), Some(GlyphId(0x8001)));
}
- Expected —
Some(GlyphId(0x8001))(32769). - Actual —
None.
Proposed fix
Add the delta with unsigned 16-bit wrapping arithmetic after the existing zero-entry check. Casting idDelta to u16 preserves its value modulo 65536, including for negative deltas.
diff --git a/src/tables/cmap/format4.rs b/src/tables/cmap/format4.rs
--- a/src/tables/cmap/format4.rs
+++ b/src/tables/cmap/format4.rs
@@ -88,8 +88,8 @@
if glyph_array_value == 0 {
return None;
}
- let glyph_id = (glyph_array_value as i16).wrapping_add(id_delta);
- return u16::try_from(glyph_id).ok().map(GlyphId);
+ let glyph_id = glyph_array_value.wrapping_add(id_delta as u16);
+ return Some(GlyphId(glyph_id));
}
} else {
I can open a PR with the fix and a synthetic regression test in tests/tables/cmap.rs.
- 主要语言
- Rust
- 星标
- 798
- 派生
- 96
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
harfbuzz/ttf-parser 的其他 Issue
-
GPOS PairPosFormat1: device/VariationIndex offsets in PairValueRecords are resolved from the wrong base, so they are always dropped可能已有人在做 @mamicicekel 于 7 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 67/100
harfbuzz/ttf-parser#245 · 1 条评论 ·
-
chore: release 0.26.0可能重新可做 @alerque 于 117 天前认领,目前没有进行中的 PR。 未关闭
harfbuzz/ttf-parser#242 · 3 条评论 · 1 个 reaction · 已指派 2 人 ·
-
help wanted
难度 4/5 3-5 天 新手友好度 45/100
harfbuzz/ttf-parser#241 · 2 条评论 ·
-
难度 5/5 一周以上 新手友好度 15/100
harfbuzz/ttf-parser#230 · 26 条评论 ·
-
难度 3/5 1-2 天 新手友好度 35/100
harfbuzz/ttf-parser#217 · 6 条评论 ·
查看 harfbuzz/ttf-parser 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
aptos-labs/aptos-core#21119 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 8 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 85/100
romnn/pdfium-embed#2 ·
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
romnn/bumpversion#11 ·