Repository navigation
libraries: Fix multiplications converted to a larger type - #7705
Merged
Merged
Conversation
Cast the first operand so that products assigned to or compared with size_t, ssize_t, long, and off_t values are computed in the wide type instead of int, which can overflow for large dimensions. This covers buffer sizes in the png and cairo drivers, gmath filter kernels, the ccmath calloc calls, linkm chunk allocation, raster row buffers, raster3d tile and volume sizes, segment addressing, and diglib reallocation. Fixes 24 CodeQL cpp/integer-multiplication-cast-to-long alerts.
This was referenced Jul 14, 2026
petrasovaa
approved these changes
Jul 14, 2026
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.
Fixes 24 CodeQL
cpp/integer-multiplication-cast-to-longalerts across the C libraries (all remaining library alerts for this rule outside lib/ogsf and lib/nviz, which are in #7704).All are the same pattern: an
int * intproduct assigned to (or compared with) a wider type (size_t,ssize_t,long,off_t), so the multiplication could overflow before widening for very large dimensions. The fix casts the first operand so the product is computed in the destination type, following the idiom from ed986f8. Touched: png/cairo driver buffer sizes, gmath filter kernels (del2g.c,getg.c), the two ccmathcalloccalls, linkm chunk allocation, raster row buffers (get_row.c,put_row.c), raster3d tile/cache/volume sizes, segment addressing, and diglib reallocation.Verification: all nine libraries compile cleanly; runtime smoke tests exercise the touched paths (r.mapcalc + r.univar round trip for raster row I/O, r3.mapcalc + r3.univar for raster3d tile I/O, d.rast renders through both the png and cairo drivers, and the earlier v.unpack testsuite run covers diglib).
This is part of a larger effort to work through the open code scanning alerts, grouped into small PRs by issue type.
Written with the assistance of Claude Code.