fix: use signed integers for canvas APIs that accept negative coordinates#1227
Merged
Brooooooklyn merged 3 commits intomainfrom Mar 16, 2026
Merged
fix: use signed integers for canvas APIs that accept negative coordinates#1227Brooooooklyn merged 3 commits intomainfrom
Brooooooklyn merged 3 commits intomainfrom
Conversation
…ates putImageData, getImageData, and createImageData used u32 for coordinate/dimension parameters, silently corrupting negative values from JavaScript. The HTML Canvas spec defines these as signed (long) or using absolute values. Changed to i32 across the call chain (ctx.rs, sk.rs, page_recorder.rs) so negative values propagate correctly to the underlying Skia FFI which already accepts signed ints. - Close #1226 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Owner
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
The as u32 cast on negative i32 wraps via two's complement (e.g. -1i32 as u32 = 4294967295), unlike unsigned_abs() which correctly produces the absolute value. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Per the spec, getImageData(sx, sy, sw, sh) with negative sw/sh should flip the origin (sx += sw, sy += sh) and use absolute values. Previously, negative f32 values were cast as u32 (saturating to 0), causing "Read pixels from canvas failed" errors. Co-Authored-By: Claude Opus 4.6 (1M context) <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.


putImageData, getImageData, and createImageData used u32 for coordinate/dimension
parameters, silently corrupting negative values from JavaScript. The HTML Canvas
spec defines these as signed (long) or using absolute values. Changed to i32 across
the call chain (ctx.rs, sk.rs, page_recorder.rs) so negative values propagate
correctly to the underlying Skia FFI which already accepts signed ints.
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com
Note
Medium Risk
Changes the JS-facing
getImageData/putImageData/createImageDataargument types and pixel IO call chain to accept negative values, which can affect rendering output and bounds handling across deferred and direct rendering paths.Overview
Fixes Canvas ImageData APIs to follow the HTML spec for signed coordinates and negative dimensions instead of silently corrupting negatives via
u32casts.This updates the Rust/N-API layer and Skia plumbing to use signed
i32for pixel read/write origins (get_image_data/read_pixels/write_pixelsandPageRecorder::get_pixels), applies spec behavior for negativegetImageDatawidth/height (flip origin + abs size), and makescreateImageDatatreat negative sizes as absolute.Adds regression tests covering
putImageDatawith negativedx/dy,getImageDatawith negativex/yand negativewidth/height, andcreateImageDatawith negative dimensions.Written by Cursor Bugbot for commit 7dd91e9. This will update automatically on new commits. Configure here.