#14632 Guard against out-of-range time step index when loading results

A case in an ensemble can have fewer time steps than the case defining the time step axis of a statistics case. The time step index was used to index m_cellScalarResults directly, reading past the end of the vector in Release where CAF_ASSERT is a no-op.
This commit is contained in:
Magne Sjaastad committed 2026-08-28 07:15:47 +02:00
1 parent 6d7959d150
commit 5f0c3f8a54
2 files changed
+22 -18

No files matched your search

@@ -1765,7 +1765,11 @@ size_t RigCaseCellResultsData::findOrLoadKnownScalarResultForTimeStep( const Rig
if ( mustBeCalculated( soilScalarResultIndex ) )
{
m_cellScalarResults[soilScalarResultIndex].resize( maxTimeStepCount() );
// A case in an ensemble can have fewer time steps than the case defining the time step axis
const size_t timeStepCount = maxTimeStepCount();
if ( timeStepIndex >= timeStepCount ) return cvf::UNDEFINED_SIZE_T;
m_cellScalarResults[soilScalarResultIndex].resize( timeStepCount );
std::vector<double>& values = m_cellScalarResults[soilScalarResultIndex][timeStepIndex];
if ( values.empty() )
@@ -1782,7 +1786,11 @@ size_t RigCaseCellResultsData::findOrLoadKnownScalarResultForTimeStep( const Rig
if ( mustBeCalculated( sgasScalarResultIndex ) )
{
m_cellScalarResults[sgasScalarResultIndex].resize( maxTimeStepCount() );
// A case in an ensemble can have fewer time steps than the case defining the time step axis
const size_t timeStepCount = maxTimeStepCount();
if ( timeStepIndex >= timeStepCount ) return cvf::UNDEFINED_SIZE_T;
m_cellScalarResults[sgasScalarResultIndex].resize( timeStepCount );
if ( m_cellScalarResults[sgasScalarResultIndex][timeStepIndex].empty() )
{
@@ -1817,6 +1825,9 @@ size_t RigCaseCellResultsData::findOrLoadKnownScalarResultForTimeStep( const Rig
if ( type == RiaDefines::ResultCatType::DYNAMIC_NATIVE && timeStepCount > 0 )
{
// A case in an ensemble can have fewer time steps than the case defining the time step axis
if ( timeStepIndex >= timeStepCount ) return cvf::UNDEFINED_SIZE_T;
m_cellScalarResults[scalarResultIndex].resize( timeStepCount );
std::vector<double>& values = m_cellScalarResults[scalarResultIndex][timeStepIndex];