Skip to content

Potential fix for code scanning alert no. 3239: Multiplication result converted to larger type#135

Closed
bniladridas wants to merge 1 commit into
mainfrom
alert-autofix-3239
Closed

Potential fix for code scanning alert no. 3239: Multiplication result converted to larger type#135
bniladridas wants to merge 1 commit into
mainfrom
alert-autofix-3239

Conversation

@bniladridas

Copy link
Copy Markdown
Member

Potential fix for https://github.com/bniladridas/hybrid-compute/security/code-scanning/3239

To fix this safely, ensure the multiplication is performed in size_t from the start by casting one operand before multiplication. That prevents intermediate int overflow and preserves behavior.

Best minimal fix in include/stb_image.h at the memset call in stbi__pic_load:

  • Change memset(result, 0xff, x * y * 4);
  • To memset(result, 0xff, (size_t)x * (size_t)y * 4u);

This keeps functionality the same (fill allocated RGBA buffer with 0xff) while making arithmetic type-safe. No new imports/dependencies are needed.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

… converted to larger type

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

☑️ I checked the pre-commit hooks and there was nothing to fix at commit 15f033c.

@github-actions github-actions Bot added the core label May 4, 2026
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>
@bniladridas

Copy link
Copy Markdown
Member Author

Fixed in #140

@bniladridas bniladridas closed this May 4, 2026
@bniladridas bniladridas deleted the alert-autofix-3239 branch May 4, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant