Skip to content

buffer: Discard pixels with negative coordinates - #9

Open
JohnAZoidberg wants to merge 1 commit into
mainfrom
fix-negative-draw-coords
Open

JohnAZoidberg wants to merge 1 commit into
mainfrom
fix-negative-draw-coords

Conversation

@JohnAZoidberg

Copy link
Copy Markdown
Member

DrawTarget implementations must silently discard out-of-bounds pixels. draw_iter only checked the upper bounds, so a negative coordinate was cast to a huge usize: with y < 0 the index is out of range and the unwrap() panics (panic = abort hangs the boot); with x < 0 the index wraps into the previous row in release builds, or panics on overflow in debug builds.

Not reachable with the current fixed layout, but any element drawn partly off-screen (e.g. a wider text box) would trigger it.

DrawTarget implementations must silently discard out-of-bounds pixels.
draw_iter only checked the upper bounds, so a negative coordinate was
cast to a huge usize: with y < 0 the index is out of range and the
unwrap() panics (panic = abort hangs the boot); with x < 0 the index
wraps into the previous row in release builds, or panics on overflow
in debug builds.

Not reachable with the current fixed layout, but any element drawn
partly off-screen (e.g. a wider text box) would trigger it.

Signed-off-by: Daniel Schaefer <[email protected]>
@github-actions

Copy link
Copy Markdown

📦 Binary Size Comparison (Nix Build)

Metric Base PR Difference
Size 756.50 KiB 757.00 KiB 📈 +512 bytes (.06%)
SHA256 90413da6fb611cbc... f734e6778c59df40... ⚠️ Changed
Full hashes
  • Base: 90413da6fb611cbcd341ea85b9564b02f3e29b0b18bcdc3b411fef2850b138fb
  • PR: f734e6778c59df4098a3b7799af757ee3657d58924c75cc20a56597f72a0f742

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the change that discards negative framebuffer coordinates.

No open issues 🎉

What changed in this PR

This PR updates framebuffer drawing to silently discard negative coordinates, as required by DrawTarget, preventing panics or writes to unintended pixels.

Changes:

  • Checks that both coordinates are nonnegative before converting them to usize.
  • Retains existing upper-bound checks and rendering of in-bounds pixels.
File Description
src/​buffer.rs Adds lower-bound checks in Buffer::draw_iter before framebuffer access.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants