3
25
Fork
You've already forked fpdf
10

fix panic on non-BMP Unicode characters (issue #112) #113

Closed
mdz wants to merge 1 commit from mdz/fpdf:fix-non-bmp-panic into main
pull from: mdz/fpdf:fix-non-bmp-panic
merge into: go-pdf:main
go-pdf:main
First-time contributor
Copy link

Fixes #112.

Text containing characters outside the Basic Multilingual Plane (code points

= U+10000, such as emoji) causes a panic during Output(). Two code paths
index into CharWidths, a fixed 65536-element slice, without proper bounds
checking.

Bug 1: generateCIDFontMap (fpdf.go)

LastRune can exceed 65535 when non-BMP characters are used, causing the
iteration for cid := startCid; cid < LastRune+1; cid++ to index past the
end of font.Cw. Fixed by capping cwLen to len(font.Cw).

Bug 2: parseHMTXTable (utf8fontfile.go)

The bounds guard char < 196608 allows indexing well beyond the 65536-element
CharWidths slice during font loading. Fixed by replacing the hardcoded
constant with len(utf.CharWidths).

Non-BMP characters are now silently skipped (treated as zero-width) rather
than causing a panic.

Made-with: Cursor

Fixes #112. Text containing characters outside the Basic Multilingual Plane (code points >= U+10000, such as emoji) causes a panic during `Output()`. Two code paths index into `CharWidths`, a fixed 65536-element slice, without proper bounds checking. **Bug 1: `generateCIDFontMap` (fpdf.go)** `LastRune` can exceed 65535 when non-BMP characters are used, causing the iteration `for cid := startCid; cid < LastRune+1; cid++` to index past the end of `font.Cw`. Fixed by capping `cwLen` to `len(font.Cw)`. **Bug 2: `parseHMTXTable` (utf8fontfile.go)** The bounds guard `char < 196608` allows indexing well beyond the 65536-element `CharWidths` slice during font loading. Fixed by replacing the hardcoded constant with `len(utf.CharWidths)`. Non-BMP characters are now silently skipped (treated as zero-width) rather than causing a panic. Made-with: Cursor

apologies.

we don't accept AI-generated code.
sorry.

(I've updated the guidelines)

apologies. we don't accept AI-generated code. sorry. (I've updated the guidelines)
sbinet closed this pull request 2026年05月18日 13:34:46 +02:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
go-pdf/fpdf!113
Reference in a new issue
go-pdf/fpdf
No description provided.
Delete branch "mdz/fpdf:fix-non-bmp-panic"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?