Skip to content

Fix integer multiplication overflow in jellyfish lake density rendering#15

Merged
highperformancecoder merged 2 commits into
masterfrom
copilot/fix-code-scanning-alerts-384
Jul 18, 2026
Merged

Fix integer multiplication overflow in jellyfish lake density rendering#15
highperformancecoder merged 2 commits into
masterfrom
copilot/fix-code-scanning-alerts-384

Conversation

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

3*width*height in jellyfish.cc performs all arithmetic in unsigned int, risking overflow before the result is widened to size_t for the vector constructor — a problem on large canvases where width*height exceeds 2³²/3 ≈ 1.4 billion.

Change

Cast the leading literal to size_t so the entire multiplication chain runs in 64-bit arithmetic:

// before
vector<unsigned char> pp(3*width*height, 255);

// after
vector<unsigned char> pp(size_t(3)*width*height, 255);

Addresses CodeQL alert cpp/integer-multiplication-cast-to-long (#384).


This change is Reviewable

Copilot AI changed the title [WIP] Fix code scanning alert 384 and address false positives Fix integer multiplication overflow in jellyfish lake density rendering Jul 18, 2026
@highperformancecoder
highperformancecoder marked this pull request as ready for review July 18, 2026 07:48
Copilot AI review requested due to automatic review settings July 18, 2026 07:48
@highperformancecoder
highperformancecoder merged commit e3f4ef7 into master Jul 18, 2026
2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a potential integer-overflow bug in lake_t::draw_density() when allocating the pixel buffer for density rendering, by widening the multiplication used to compute the vector size so it can’t overflow in 32-bit unsigned arithmetic on large canvases.

Changes:

  • Widen 3*width*height to size_t arithmetic by casting the leading literal to size_t in the pp buffer allocation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants