Skip to content

Conversation

Copy link

Copilot AI commented Nov 21, 2025

Addresses review feedback on PR #280 regarding potential integer overflow in width * height * getC() expression when checking image dimensions.

Analysis

With maxDim = 65536, the maximum product width * height is 4,294,967,296, which fits in 64-bit size_t. Even with typical channel counts (1-4), the expression width * height * getC() doesn't overflow size_t before the INT_MAX comparison.

Overflow would only occur if:

  • Running on 32-bit systems (where size_t is 32-bit), or
  • numChannels exceeds ~4 million

The existing check is safe on 64-bit systems with reasonable channel counts. The suggested overflow-safe multiplication approach would add defensive checks that may not be necessary given the maxDim constraint, though they would provide additional safety on 32-bit platforms.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix maxDim handling in image loaders based on review feedback Clarify overflow analysis for maxDim-constrained image dimensions Nov 21, 2025
Copilot AI requested a review from kraszkow November 21, 2025 17:20
@kraszkow kraszkow closed this Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants