From 55fb8105e2d73450358f8411f46df0405464890a Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 7 Aug 2026 15:34:43 +0200 Subject: [PATCH] Do not read NNC geometry out of bounds on INIT and grid file mismatch transferStaticNNCData() takes the connection count from the INIT file using ecl_nnc_data_get_size(), but iterates the geometry from the grid file using ecl_nnc_geometry_iget(). The two counts were only compared in an assert, which is compiled out in release builds, so an INIT file out of sync with the grid reads past the end of the geometry vector inside resdata. Compare the counts at run time, log a warning and iterate the smaller of the two. Both nncConnections and transmissibilityValuesTemp are filled in the same loop and stay aligned. --- .../FileInterface/RifReaderEclipseOutput.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.cpp b/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.cpp index 0a8468b334..8070184202 100644 --- a/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.cpp +++ b/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.cpp @@ -62,6 +62,7 @@ #include #include +#include #include // Needed for HUGE_VAL on Linux #include #include @@ -719,7 +720,18 @@ void RifReaderEclipseOutput::transferStaticNNCData( const ecl_grid_type* mainEcl { int numNNC = ecl_nnc_data_get_size( tran_data ); int geometrySize = ecl_nnc_geometry_size( nnc_geo ); - CAF_ASSERT( numNNC == geometrySize ); + + if ( numNNC != geometrySize ) + { + // The transmissibility data is read from the INIT file, the geometry from the grid file. If the two files are out of + // sync, iterating the geometry using the data count reads out of bounds. Use the smallest count. + RiaLogging::warning( std::format( "NNC data count ({}) does not match NNC geometry count ({}), importing {} connections.", + numNNC, + geometrySize, + std::min( numNNC, geometrySize ) ) ); + + numNNC = std::min( numNNC, geometrySize ); + } if ( numNNC > 0 ) {