engine: net_chan: check BZ2 functions return value and log if it's not BZ_OK

This commit is contained in:
Alibek Omarov 2024-11-28 19:27:13 +03:00
parent 888599677e
commit df4194ca57

View file

@ -754,7 +754,7 @@ static void Netchan_CreateFragments_( netchan_t *chan, sizebuf_t *msg )
byte pbOut[0x10000]; byte pbOut[0x10000];
uint uSourceSize = MSG_GetNumBytesWritten( msg ); uint uSourceSize = MSG_GetNumBytesWritten( msg );
uint uCompressedSize = MSG_GetNumBytesWritten( msg ) - 4; uint uCompressedSize = MSG_GetNumBytesWritten( msg ) - 4;
if( !BZ2_bzBuffToBuffCompress( pbOut, &uCompressedSize, MSG_GetData( msg ), uSourceSize, 9, 0, 30 )) if( BZ2_bzBuffToBuffCompress( pbOut, &uCompressedSize, MSG_GetData( msg ), uSourceSize, 9, 0, 30 ) == BZ_OK )
{ {
if( uCompressedSize < uSourceSize ) if( uCompressedSize < uSourceSize )
{ {
@ -1180,12 +1180,20 @@ qboolean Netchan_CopyNormalFragments( netchan_t *chan, sizebuf_t *msg, size_t *l
#if !XASH_DEDICATED #if !XASH_DEDICATED
byte buf[0x10000]; byte buf[0x10000];
uint uDecompressedLen = sizeof( buf ); uint uDecompressedLen = sizeof( buf );
int bz2_err = BZ2_bzBuffToBuffDecompress( buf, &uDecompressedLen, MSG_GetData( msg ) + 4, MSG_GetNumBytesWritten( msg ) - 4, 1, 0 );
BZ2_bzBuffToBuffDecompress( buf, &uDecompressedLen, MSG_GetData( msg ) + 4, MSG_GetNumBytesWritten( msg ) - 4, 1, 0 ); if( bz2_err == BZ_OK )
memcpy( msg->pData, buf, uDecompressedLen ); {
size = uDecompressedLen; size = uDecompressedLen;
memcpy( msg->pData, buf, size );
}
else
{
Con_Printf( S_ERROR "%s: BZ2 decompression failed (%d)\n", __func__, bz2_err );
return false;
}
#else #else
Host_Error( "%s: BZ2 compression is not supported for server", __func__ ); Host_Error( "%s: BZ2 compression is not supported for server\n", __func__ );
#endif #endif
} }
else if( !chan->use_bz2 && LZSS_IsCompressed( MSG_GetData( msg ), size )) else if( !chan->use_bz2 && LZSS_IsCompressed( MSG_GetData( msg ), size ))