mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 07:00:17 -05:00
#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.
This commit is contained in:
1 parent
a4b8570b3a
commit
203cf83334
1 file changed
+18
-7
@@ -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<RiaDefines::PhaseType> 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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user