Fix integer overflow in csr_offsets subscripts#5950
Closed
q10 wants to merge 1 commit into
Closed
Conversation
Contributor
|
@q10 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D109620546. |
Summary:
In `csr2csc_template_`, the subscript expressions used to index into
`csr_offsets` computed `table_to_feature_offset[N] * B` as `int * int`,
which overflows for large values of B or feature offset counts. This can
lead to out-of-bounds array access.
Four sites are fixed by casting one operand to `size_t` before the
multiplication, which promotes the other `int` operand via the usual
arithmetic conversions, making the product safe:
- `nnz` computation (both subscripts)
- `NS` computation (second subscript — first already had the cast)
- `FBo` subscript
Also fix type-safety issues in the inner loop value assignment:
- Use `pair_t{}` explicitly instead of relying on CTAD from `std::pair{}`
- Cast `scale_factor` (double) to `scalar_t` before multiplication to
avoid implicit narrowing
- Replace hardcoded `1.0f` fallback weight with `scalar_t{1}`
Reviewed By: colin2328
Differential Revision: D109620546
Contributor
|
This pull request has been merged in ac03680. |
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:
In
csr2csc_template_, the subscript expressions used to index intocsr_offsetscomputedtable_to_feature_offset[N] * Basint * int,which overflows for large values of B or feature offset counts. This can
lead to out-of-bounds array access.
Four sites are fixed by casting one operand to
size_tbefore themultiplication, which promotes the other
intoperand via the usualarithmetic conversions, making the product safe:
nnzcomputation (both subscripts)NScomputation (second subscript — first already had the cast)FBosubscriptAlso fix type-safety issues in the inner loop value assignment:
pair_t{}explicitly instead of relying on CTAD fromstd::pair{}scale_factor(double) toscalar_tbefore multiplication toavoid implicit narrowing
1.0ffallback weight withscalar_t{1}Reviewed By: colin2328
Differential Revision: D109620546