Potential fix for code scanning alert no. 3240: Multiplication result converted to larger type#134
Closed
bniladridas wants to merge 1 commit into
Closed
Potential fix for code scanning alert no. 3240: Multiplication result converted to larger type#134bniladridas wants to merge 1 commit into
bniladridas wants to merge 1 commit into
Conversation
… converted to larger type Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|
Contributor
|
☑️ I checked the pre-commit hooks and there was nothing to fix at commit |
bniladridas
added a commit
that referenced
this pull request
May 4, 2026
Combines all 15 automated code scanning alert fixes for multiplication result converted to larger type. These changes span `include/stb_image.h`, `include/stb_image_write.h`, and `src/preprocess.c` with consistent application of `size_t` casts to prevent integer overflow before conversion to larger types. Overflow checks are added where allocation sizes are stored back into `int` variables such as `out_size`. > [!NOTE] > Merging this pull request will automatically close #125, #126, #127, #128, #129, #130, #131, #132, #133, #134, #135, #136, #137, #138, #139 --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Niladri Das <bniladridas@users.noreply.github.com>
Member
Author
|
Fixed in #140 |
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.
Potential fix for https://github.com/bniladridas/hybrid-compute/security/code-scanning/3240
The correct fix is to force the allocation-size multiplication to be performed in
size_trather thanint, so intermediate overflow cannot happen inintarithmetic.Best single change: in
include/stb_image.hat the allocation line in the PSD loader branch (around line 6902), replacestbi__malloc(4 * w * h)withstbi__malloc((size_t)4 * (size_t)w * (size_t)h)(or equivalent4u/size_tpromotion). This keeps functionality unchanged (same intended byte count), but ensures type-safe evaluation before passing to allocator. No new imports/dependencies are needed becausesize_tis already available via existing standard headers in this file context.Suggested fixes powered by Copilot Autofix. Review carefully before merging.