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