MetOffice / opsinputs

JEDI library generating VarObs and Cx files
BSD 3-Clause "New" or "Revised" License
4 stars 1 forks source link

Fix out-of-bounds bug #125

Closed ctgh closed 2 years ago

ctgh commented 2 years ago

In the routine opsinputs_fill_fillelementtype2dfromsimulatedvariable_records, there is a short piece of code that sets flags for any unused levels in a record to failed:

    El2(iObs, numLevels + 1 : JediToOpsLayoutMapping % MaxNumLevelsPerObs) % Flags = &
      ibset(0, FinalRejectFlag)

However, in certain circumstances (e.g. a prescribed number of model levels, which occurs for averaged sonde data), this can lead to an out-of-bounds error if numLevels + 1 is greater than the length of the second dimension of El2. In most cases nothing obvious happens (although memory corruption could occur behind the scenes), but occasionally there is a segfault.

To fix this the code has been modified to compare numLevels against size(El2, 2) and only fill in the flags if there are actually superfluous levels in El2.

Fixes #124