Bugfix: Handle TypedArrays and Buffers in deep-merge/clone#1744
Draft
ykw9263 wants to merge 5 commits into
Draft
Bugfix: Handle TypedArrays and Buffers in deep-merge/clone#1744ykw9263 wants to merge 5 commits into
ykw9263 wants to merge 5 commits into
Conversation
blikblum
reviewed
Jun 26, 2026
| function deepClone(obj) { | ||
| let result = obj; | ||
| if (obj && typeof obj == 'object') { | ||
| if (isTypedArray(obj)) { |
Member
There was a problem hiding this comment.
Where deepClone is called in this code path?
I would like to avoid cloning buffer / UintArray in name of efficiency
| return ( | ||
| isObject(item) && | ||
| item.length !== undefined && | ||
| (item instanceof Uint8Array || |
Member
There was a problem hiding this comment.
AFAIK we only support Uint8Array
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.
What kind of change does this PR introduce?
This fixes a bug mentioned in #1743 where providing font buffers crashes table generation.
In
lib\table\utils.js,deepMergeanddeepClone()copy properties key by key includingBufferandUint8Arraywithout inheriting the class. This causes the merged font buffer failing to be recognised byPDFFontFactorywhich relies oninstanceofto determine the type of font sources.This PR changes the behaviour of
deepMerge()anddeepClone()to clone TypedArrays and Buffers using.slice()andBuffer.from(buffer)respectively.Additional unit tests (fonts in tables, deep-merging buffers) are added for the changes.
Checklist:
TODO:
pdfkit/lib/table/style.js
Line 118 in 2fdafa2
pdfkit/lib/table/style.js
Line 62 in 2fdafa2
pdfkit/lib/table/normalize.js
Line 96 in 2fdafa2