Skip to content

Conversation

Copy link

Copilot AI commented Nov 25, 2025

Addressed review feedback on PR #280 regarding potential underflow in H-1-h expression when H=0.

Analysis

The bot's concern about underflow was incorrect. When H=0, the loop condition for (size_t h = 0; h < H; ++h) evaluates to 0 < 0 (false), preventing loop body execution. The expression H-1-h is never evaluated, so no underflow can occur.

Conclusion

No code changes required. The existing implementation correctly handles zero dimensions through the loop guard itself.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

kraszkow and others added 2 commits November 21, 2025 11:01
This patch hardens ImageBuffer and the PFM loader against malformed or
malicious inputs:

- Switch width/height/channels from int to size_t to avoid signed overflow.
- Add maxDim guard (64K) and reject images whose total pixel count exceeds
  int limits to prevent integer multiplication overflow.
- Validate pixel reads during PFM parsing and fail early on read errors.
- Use overflow-safe width*height*C checks before allocating the buffer.
- Add static_assert ensuring size_t is 64-bit on supported platforms.

These changes prevent tiny allocations followed by large writes caused by
untrusted PFM headers (e.g., malicious W/H/C), removing the possibility of
heap-based out-of-bounds writes.
Copilot AI changed the title [WIP] Fix handling loop execution for zero height in image loaders Acknowledge loop execution behavior for zero height - no validation needed Nov 25, 2025
Copilot AI requested a review from kraszkow November 25, 2025 08:39
@kraszkow kraszkow force-pushed the kraszkow/devel branch 2 times, most recently from 03e7afe to 33fd2e1 Compare November 25, 2025 13:43
@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