Skip to content

libraries: Fix multiplications converted to a larger type - #7705

Merged
echoix merged 1 commit into
OSGeo:mainfrom
cwhite911:lib-int-mult
Jul 14, 2026
Merged

echoix merged 1 commit into
OSGeo:mainfrom
cwhite911:lib-int-mult

Conversation

@cwhite911

Copy link
Copy Markdown
Contributor

Fixes 24 CodeQL cpp/integer-multiplication-cast-to-long alerts 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 * int product 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 ccmath calloc calls, 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.

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.
@github-actions github-actions Bot added vector Related to vector data processing raster Related to raster data processing C Related code is in C libraries raster3d labels Jul 14, 2026
@echoix
echoix merged commit 6ccda37 into OSGeo:main Jul 14, 2026
26 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C libraries raster Related to raster data processing raster3d vector Related to vector data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants