GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libgfortran

Detect and handle overflowing coarray sizes

libgfortran now prevents crashes and data corruption by detecting and handling integer overflows in coarray size calculations.

This commit introduces robust overflow checking for coarray size calculations within libgfortran’s shared memory implementation. Previously, multiplying the per-image size by the number of images could result in an integer overflow, leading to an incorrectly small allocated size and potential data corruption. The fix saturates size arithmetic at SIZE_MAX and rejects requests for sizes that cannot be rounded up to a power of two, ensuring that such operations fail gracefully with appropriate error reporting.

In Details

This commit addresses an integer overflow vulnerability in libgfortran's caf_shmem implementation. Specifically, _gfortran_caf_register could overflow when calculating the total size (per-image size * num_images) because it used size_t without checking for overflow. This could lead to a wrapped-around small size, successful allocation (STAT=0), but a severely undersized coarray. The fix introduces mul_size_sat to perform saturated multiplication, ensuring calculations do not wrap around. It also modifies allocator_shared_malloc to reject sizes that cannot be rounded up to a powe…

For Context
libgfortran
The runtime library for the GNU Fortran compiler (gfortran). It provides support for language features, intrinsic procedures, and I/O operations.
caf_shmem
Coarray Fortran Shared Memory. A specific implementation within libgfortran for handling coarray communication and data distribution using shared memory on multi-node systems.
coarray
A Fortran language feature that allows for parallel programming by providing a syntax for declaring objects that are implicitly distributed across images (processes or threads).
SIZE_MAX
A C preprocessor macro defined in <stdint.h> representing the maximum value for an object of type size_t. Used here to detect and prevent integer overflow.
STAT=
A Fortran specifier used with I/O statements and allocation operations to indicate the status of the operation. A value of 0 typically means success, while a non-zero value indicates an error.
Filed Under: libgfortrancoarrayoverflowsecurity