diff --git a/simgear/io/sg_binobj.cxx b/simgear/io/sg_binobj.cxx index 82f1b458..5e4e5b1a 100644 --- a/simgear/io/sg_binobj.cxx +++ b/simgear/io/sg_binobj.cxx @@ -42,6 +42,7 @@ #include #include +#include #include #include @@ -563,6 +564,12 @@ bool SGBinObject::read_bin( const SGPath& file ) { // read headers unsigned int header; sgReadUInt( fp, &header ); + + if (sgReadError()) { + gzclose(fp); + throw sg_io_exception("Unable to read BTG header: " + simgear::strutils::error_string(errno), sg_location(file)); + } + if ( ((header & 0xFF000000) >> 24) == 'S' && ((header & 0x00FF0000) >> 16) == 'G' ) {