Check a font is flagged before reading the keys only a used font has - #19
Merged
Merged
Conversation
_putpatterns() builds a resource dictionary for an SVG background by picking out the fonts an SVG has flagged, but it tests $font['used'] and $font['type'] before it tests $font['fo']. A core font that has drawn nothing yet has neither key, so any page whose only text lives inside a repeating SVG background raises "Undefined array key" on PHP 8 — and a page like that is exactly when the loop runs. Test the flag first. Nothing else changes: the output for such a document is byte for byte what it was. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Summary
A follow-on from #18, which found this defect in the twin code path but left it alone as out of scope.
BackgroundWriter::writePatterns()writes a resource dictionary for an SVG used as a repeating background, and picks the fonts for it out of$this->mpdf->fonts:usedandtypeare read beforefo— but a core font that has not drawn anything yet carries neither key. So the loop raises Undefined array key "used" on PHP 8 for any page whose only text lives inside the SVG background, which is precisely the situation in which this loop runs at all.Testing the flag first is enough. This is not a mirror of anything upstream; the same shape landed in
FormWriterin #18, where the identical order brokeIssue539TestandIssue990Test.Try it
On
gravitypdf, withdisplay_errorson:On this branch, nothing. Note the
<div>has no text of its own — that is what leaves the core font registered but unused.Test plan
composer test— 1050 tests, 2533 assertions, green (gravitypdfis at 1048).composer cs— clean.gravitypdf, none new.tests/Mpdf/BackgroundPatternResourcesTest.php— both cases error ongravitypdf, pass here.gravitypdf's once the creation date is normalised, so this is the warning and nothing else.More info
Behaviour is unchanged
Reordering the guards cannot change which fonts are listed:
fofo, TTF,usedfalsefo, TTF,usedtrue, SIP/SMPfotypeis nowisset()-guarded too, matching howResourceWriter::writeResources()reads the same array.The test
Two cases, both rendering the same page:
/PatternType 1is in the output, so the tiling-pattern branch really ran — without that, a passing test would prove nothing, since PHPUnit's warning-to-error conversion is what catches the regression./Resourcesobject still names the font its Form XObject draws with, so the reorder has not quietly dropped anything. The fixture SVG carries a<text>element for that reason; none of the existing SVG fixtures do.Relationship to #18
Independent — different file, no conflict, either order. #18 fixes the same defect in
FormWriter::getResources(), which is new code there; this one has been inBackgroundWriterall along.