NOAA-EMC / NCEPLIBS-grib_util

This is a collection of NCEP GRIB related utilities.
Other
21 stars 11 forks source link

in degrib2, prvtime() subroutine, some valid pdt values cause 0 to be attempted to be used as array index, causing memory problems #228

Closed edwardhartnett closed 1 year ago

edwardhartnett commented 1 year ago

In degrib2, in prvtime.F90, we have:

data ipos2 /70, 26, 33, 27, 29, 28, 42, 41, 270, 22, 30, 0, 0, 32, & 35, 430, 33, 1090/

Later we have:

 iutpos2 = ipos2(ipdtn)
 selectcase(ipdtmpl(iutpos2))

Note that if ipos2(ipdtn) is 0, then we will attempt to do an access of array element 0 of ipdtmpl(), which does not exist, causing memory errors.

This happens some pdts don't use the secondary time units. In this case, the original programmer has put a 0 in the ipos2 array. However, this is wrong because it is still accessed, even though the secondary time is not used.