From 203cf83334b6dc0d77350fd05f2f03db8633f286 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 22 Jun 2026 15:50:52 +0200 Subject: [PATCH] #14283 Guard missing INTEHEAD keyword in Eclipse file readers ecl_file_iget_named_kw() performs an unchecked vector access in ERT and crashes (SIGSEGV) when the requested keyword does not exist in the active file view. findAvailablePhases, readUnitsType and isExportedFromIntersect called it for INTEHEAD without first checking the keyword is present. Guard each call with ecl_file_get_num_named_kw(), matching the existing pattern in this file. --- .../RifEclipseOutputFileTools.cpp | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/ApplicationLibCode/FileInterface/RifEclipseOutputFileTools.cpp b/ApplicationLibCode/FileInterface/RifEclipseOutputFileTools.cpp index 6e721c7197..29e4acc333 100644 --- a/ApplicationLibCode/FileInterface/RifEclipseOutputFileTools.cpp +++ b/ApplicationLibCode/FileInterface/RifEclipseOutputFileTools.cpp @@ -513,10 +513,14 @@ int RifEclipseOutputFileTools::readUnitsType( const ecl_file_type* ecl_file ) if ( ecl_file ) { - ecl_kw_type* kwINTEHEAD = ecl_file_iget_named_kw( ecl_file, INTEHEAD_KW, 0 ); - if ( kwINTEHEAD ) + // ecl_file_iget_named_kw() does an unchecked vector access; guard against a missing keyword. + if ( ecl_file_get_num_named_kw( ecl_file, INTEHEAD_KW ) > 0 ) { - unitsType = ecl_kw_iget_int( kwINTEHEAD, INTEHEAD_UNIT_INDEX ); + ecl_kw_type* kwINTEHEAD = ecl_file_iget_named_kw( ecl_file, INTEHEAD_KW, 0 ); + if ( kwINTEHEAD ) + { + unitsType = ecl_kw_iget_int( kwINTEHEAD, INTEHEAD_UNIT_INDEX ); + } } } @@ -582,11 +586,15 @@ std::set RifEclipseOutputFileTools::findAvailablePhases( { if ( ecl_file ) { - const ecl_kw_type* intehead = ecl_file_iget_named_kw( ecl_file, INTEHEAD_KW, 0 ); - if ( intehead ) + // ecl_file_iget_named_kw() does an unchecked vector access; guard against a missing keyword. + if ( ecl_file_get_num_named_kw( ecl_file, INTEHEAD_KW ) > 0 ) { - int phases = ecl_kw_iget_int( intehead, INTEHEAD_PHASE_INDEX ); - return RiaOpmParserTools::phasesFromInteheadValue( phases ); + const ecl_kw_type* intehead = ecl_file_iget_named_kw( ecl_file, INTEHEAD_KW, 0 ); + if ( intehead ) + { + int phases = ecl_kw_iget_int( intehead, INTEHEAD_PHASE_INDEX ); + return RiaOpmParserTools::phasesFromInteheadValue( phases ); + } } } @@ -642,6 +650,9 @@ bool RifEclipseOutputFileTools::isExportedFromIntersect( const ecl_file_type* ec { // This code is taken from ecl_file_get_ecl_version() in ecl_file.cpp + // ecl_file_iget_named_kw() does an unchecked vector access; guard against a missing keyword. + if ( ecl_file_get_num_named_kw( ecl_file, INTEHEAD_KW ) == 0 ) return false; + ecl_kw_type* intehead_kw = ecl_file_iget_named_kw( ecl_file, INTEHEAD_KW, 0 ); if ( !intehead_kw ) return false;