Repository navigation
fix(font): a freed font's subset could be embedded for the next font - #55
Open
serpentblade wants to merge 1 commit into
Open
serpentblade wants to merge 1 commit into
serpentblade wants to merge 1 commit into
Conversation
TtfSubsetter's static cache was keyed by spl_object_id() of the source font. PHP reuses a freed object's id, so in a long-running process (Octane, queue workers, batch scripts) a font loaded after another was freed could be handed the old font's subset. Liberation Sans Bold got Regular's bytes: both share a glyph order, so the same text gave the same key, and the PDF embedded the wrong font. Each source font now gets a cache id from a counter that is never reused, held in a WeakMap so it goes away with the font. The cache's size and eviction are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a long-running process (Octane, queue workers, batch scripts), a PDF could embed the wrong font. Render with Liberation Sans Regular, let it be freed, then render with Bold: the second PDF embeds Regular.
TtfSubsetter's static cache was keyed byspl_object_id()of the font, and PHP reuses a freed object's id. The two fonts share a glyph order, so the same text produced the same key. Each font now gets a cache id from a counter that is never reused, held in aWeakMapso it goes away with the font. Cache size and eviction are unchanged.One regression test, failing before the fix. Full suite and phpstan pass on PHP 8.2 and 8.4.
🤖 Generated with Claude Code