extmod/modframebuf: Fix 16-bit integer overflow in pixel index arithmetic. - #19586
Closed
Yudis-bit wants to merge 1 commit into
Closed
extmod/modframebuf: Fix 16-bit integer overflow in pixel index arithmetic.#19586Yudis-bit wants to merge 1 commit into
Yudis-bit wants to merge 1 commit into
Conversation
…etic. On platforms with 16-bit int, the expression x + y * fb->stride overflows when y >= 128 with a 256-wide framebuffer, causing out-of-bounds reads and writes. Cast x and y to size_t in all pixel-index expressions to force promotion to a type wide enough for the full framebuffer address space. The two existing size_t index declarations (horizontal line and vertical line drawing) already handled the promotion correctly; this change covers the 12 remaining expressions in the RGB565, GS2_HMSB, GS4_HMSB, and GS8 pixel functions. Fixes: micropython#19431 Signed-off-by: Yudistira Putra <85178972+Yudis-bit@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19586 +/- ##
=======================================
Coverage 98.59% 98.59%
=======================================
Files 182 182
Lines 23299 23299
Branches 5 5
=======================================
Hits 22971 22971
Misses 327 327
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
Thanks for the contribution, but:
|
|
Code size report: |
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.
Problem
On platforms with 16-bit int, the expression
x + y * fb->strideoverflows wheny >= 128with a 256-wide framebuffer, causing out-of-bounds reads and writes. Fixes #19431.Fix
Cast x and y to size_t in all 12 pixel-index expressions in the RGB565, GS2, GS4, and GS8 pixel functions. The two existing size_t declarations (h/v line drawing) already handled promotion correctly.
Verification
No behavioral change on 32-bit-int platforms. On 16-bit-int platforms, the cast prevents overflow for all framebuffer sizes up to SIZE_MAX.
Signed-off-by: Yudistira Putra 85178972+Yudis-bit@users.noreply.github.com