Repository navigation
Conversation
The matrix stack counters start at 1 for their initial matrices. Reject pops when the counter is <= 1 to prevent out-of-bounds access and correctly report SW_STACK_UNDERFLOW.
Author
|
hey @raysan5, just following up on this PR, it's a pretty small fix, could you pls review? thanks for your time. |
Owner
|
@Bigfoot71 it looks good to me, despite the apparently AI generated issue, but please, could you take a second look to confirm merge? |
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.
Summary
Fix matrix stack underflow in
swPopMatrix()for all three matrix modes insrc/external/rlsw.h.Closes #6361
Problem
during initialization, projection, modelview, and texture matrix stack counters are initialized to
1, representing their initial matrices. but,swPopMatrix()previously checked whether the respective counter was<= 0before decrementing it.When popping a stack containing only its initial matrix (
counter == 1), the check was bypassed. The counter was decremented to zero, and the subsequent- 1index calculation underflowed theuint32_tcounter to4294967295.resulted in
RLSW.currentMatrixpointing outside the corresponding matrix stack. subsequent matrix operations then caused out-of-bounds writes and AddressSanitizer segmentation faults.affected
SW_PROJECTION,SW_MODELVIEW, andSW_TEXTURE.Solution
Changed the underflow checks for all three matrix stacks from
<= 0to<= 1.This prevents popping the initial matrix, sets
SW_STACK_UNDERFLOW, and preserves the existing matrix stack state.Testing
I verified using a standalone
rlswtest harness compiled with Clang 18.1.3, AddressSanitizer, and UndefinedBehaviorSanitizer:SW_STACK_UNDERFLOW(1284) without sanitizer errors.swPushMatrix(), matrix transformations, andswPopMatrix()operations were tested across all three modes and continued to work correctly.standalone reproducer was tested on Ubuntu 24.04.3 LTS under WSL2.