Repository navigation
Respect Buffer view bounds in fromBitmap and quantize - #1419
Open
Shrusti-pk wants to merge 1 commit into
Open
Shrusti-pk wants to merge 1 commit into
Shrusti-pk wants to merge 1 commit into
Conversation
This branch has not been deployed
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's Changing and Why
Jimp.fromBitmap()and thequantizeplugin readdata.bufferand ignorebyteOffset/byteLength. Node serves small Buffers (under 4 KiB, fromBuffer.from()orBuffer.allocUnsafe()) as slices of a shared 8 KiB pool, so.bufferis the whole pool, not the image.fromBitmap: a Buffer also matches theUint8Arraybranch, which overwrites the copy made just above it withBuffer.from(data.buffer). The bitmap then aliases the pool: pixels come from unrelated Buffers in the process, and writes to the image overwrite them.quantize: image-q'sPointContainer.fromUint8Arrayreads.bufferitself, so a bounded view is not enough and it now gets a copy. After a smallcrop()(which usesBuffer.allocUnsafe),quantize()built its palette from pool memory and returned an 8 KiB bitmap.Repro on Node 22 before this change:
What else might be affected
A Buffer passed to
fromBitmapis now actually copied, as that branch intended, so editing the image no longer writes back into the caller's Buffer.Uint8Array/Uint8ClampedArrayinput is still wrapped without a copy, limited to the view's own bytes.Tasks
jimp.d.tsThe new tests fail before the change and pass after.
pnpm build,pnpm lint,pnpm testandpnpm test:browserpass locally.