Skip to content

Range check mask_table entries before writing maskmap - #1920

Open
arpitjain099 wants to merge 1 commit into
NOAA-GFDL:mainfrom
arpitjain099:fix/mask-table-index-range
Open

arpitjain099 wants to merge 1 commit into
NOAA-GFDL:mainfrom
arpitjain099:fix/mask-table-index-range

Conversation

@arpitjain099

Copy link
Copy Markdown

parse_mask_table_2d checks quite a lot before it uses the file: nmask against the record count, the layout against size(maskmap), ntiles, npes. Then it writes at whatever indices the records carried:

call mpp_broadcast(mask_list, 2*nmask, mpp_root_pe())
do n = 1, nmask
   maskmap(mask_list(n,1),mask_list(n,2)) = .false.
enddo

Running that loop with the shapes a 2 by 3 layout gives, and an entry of 9,9:

with -fcheck=bounds : Fortran runtime error: Index '9' of dimension 2 of array 'maskmap' above upper bound of 3
without             : runs to completion, maskmap unchanged, exit 0

The second line is the one that matters: production builds do not carry -fcheck, so a mask table with a typo writes a .false. somewhere outside the array and the run continues.

The check compares each index against size(maskmap, ...) and raises the same mpp_error(FATAL, ...) the routine already uses for the other malformed cases. parse_mask_table_3d has the same loop and gets the same treatment.

I could not build FMS here, it needs MPI and netCDF, so the runs above are that loop with the same array shapes rather than the library.

parse_mask_table validates nmask, the layout against size(maskmap), ntiles,
npes and the record count, and then writes maskmap at the row and column the
file supplies without checking either. An entry outside the layout gives a
bounds error in a checked build and a silent write past the array otherwise.
Both the 2d and 3d variants have it.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>

This branch has not been deployed

No deployments
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.

1 participant