fix: clamp start/end in slice_backward to prevent out-of-bounds kernel write#2187
Open
physics31415926 wants to merge 4 commits intoflagos-ai:masterfrom
Open
fix: clamp start/end in slice_backward to prevent out-of-bounds kernel write#2187physics31415926 wants to merge 4 commits intoflagos-ai:masterfrom
physics31415926 wants to merge 4 commits intoflagos-ai:masterfrom
Conversation
Also add regression test for oob start case.
28228db to
2ccbd7f
Compare
tengqm
reviewed
Apr 1, 2026
tengqm
reviewed
Apr 1, 2026
Contributor
tengqm
left a comment
There was a problem hiding this comment.
picky nits.
otherwise lgtm.
delete repeative assignment Co-authored-by: Qiming Teng <[email protected]> Signed-off-by: Physics <[email protected]>
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
When
end > dim_size,slice_lenwas computed without clamping, causingdim_index = start + slice_idx * stepto exceeddim_size. The kernel thenwrote to an out-of-bounds address, triggering
cudaErrorIllegalAddress.PyTorch allows
endto exceed the dimension size (it clamps silently), butthe FlagGems kernel did not handle this case.
Fix
Clamp
startandendto[0, dim_size] before computingslice_len,matching PyTorch's behavior.
Test
Added
test_slice_backward_oob_endto reproduce the out-of-bounds case.