cmap format 4 drops glyph IDs above 32767 in the glyphIdArray path
まだ誰も着手していません。
- #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 ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
harfbuzz/ttf-parser#242 · コメント 3 件 · リアクション 1 件 · 担当者 2 名 ·
-
help wanted
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
harfbuzz/ttf-parser#241 · コメント 2 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 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 ·