fix: add bounds clamping in c_display::fill_rect() for negative coordinates - #81
Open
srpatcha wants to merge 3 commits into
Open
fix: add bounds clamping in c_display::fill_rect() for negative coordinates#81srpatcha wants to merge 3 commits into
srpatcha wants to merge 3 commits into
Conversation
The base class fill_rect() computed framebuffer offsets without validating that coordinates are non-negative, causing out-of-bounds memory writes with negative inputs. The child class c_surface already had this protection.
srpatcha
force-pushed
the
fix/display-fill-rect-bounds
branch
from
April 25, 2026 02:16
638bec2 to
06a08dc
Compare
…n support - Add c_progress_bar class inheriting from c_wnd - Support horizontal and vertical orientations - Implement color gradient fill based on progress - Add animated fill with configurable speed - Include percentage text display - Support completion callback - Add min/max range with bounds clamping - Add test file for widget validation Bug-fix: Added bounds clamping for value setting Signed-off-by: Srikanth Patchava <spatchava@meta.com>
The base draw_pixel() only checked if coordinates exceeded width/height, but not if they were negative. Negative coordinates cause out-of-bounds memory writes by indexing m_phy_fb at a negative offset. Same class of bug as the recently-fixed fill_rect() in c_display. Signed-off-by: Srikanth Patchava <spatchava@meta.com>
Author
|
Friendly ping — this adds bounds clamping in c_display::fill_rect() for negative coordinates to prevent out-of-bounds memory access. Ready for review. |
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.
Fix buffer underflow from negative coordinates in c_display::fill_rect()
Problem
c_display::fill_rect()insrc/core/display.hcomputes framebuffer offsets usingy * _width + x0without validating that coordinates are non-negative. Negative coordinates cause out-of-bounds memory writes to the framebuffer, potentially corrupting memory or causing crashes.Root Cause
The child class
c_surface::fill_rect()properly clamps coordinates, but the base classc_display::fill_rect()does not. While the inner loop checksx < _widthandy < _heightfor upper bounds, it does not check for negative values. The framebuffer pointer arithmetic&((unsigned short*)m_phy_fb)[y * _width + x0]will produce an address before the buffer when x0 or y is negative.Fix
Added bounds clamping at the start of the direct framebuffer path (after the driver delegation checks):
Testing
fill_rect()with negative coordinates (e.g.,fill_rect(-10, -5, 50, 50, color)) and verify no crash occurs.Impact
Affects any GuiLite application that passes negative coordinates to the base display class's fill_rect. This is a memory safety issue.