fix: invalid data access of data field

bgl_babylon.cc

fix #768
This commit is contained in:
YiFang Xiao 2023-06-03 09:27:07 +08:00 committed by xiaoyifang
parent 49c6ae7032
commit 0c7d7ada21

View file

@ -131,7 +131,7 @@ void Babylon::close()
bool Babylon::readBlock( bgl_block &block )
{
if( gzeof( file ) || file == NULL )
if ( file == NULL || gzeof( file ) )
return false;
block.length = bgl_readnum( 1 );
@ -346,19 +346,19 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler )
{
switch( block.type )
{
case 2:
{
pos = 0;
len = (unsigned char)block.data[pos++];
if( pos + len > block.length )
case 2: {
// the block data may have length==0
if ( block.length == 0 )
break;
std::string filename( block.data+pos, len );
pos = 0;
len = (unsigned char)block.data[ pos++ ];
if ( pos + len > block.length )
break;
std::string filename( block.data + pos, len );
//if (filename != "8EAF66FD.bmp" && filename != "C2EEF3F6.html") {
pos += len;
pos += len;
if ( resourceHandler )
resourceHandler->handleBabylonResource( filename,
block.data + pos,
block.length - pos );
resourceHandler->handleBabylonResource( filename, block.data + pos, block.length - pos );
break;
}
case 1: