engine: tighten file fragment msg by the (possibly) trunctated frag_message

This commit is contained in:
Alibek Omarov
2026-05-23 20:27:45 +05:00
parent 8b89bdca6f
commit 996dcc637d

View File

@@ -1158,7 +1158,7 @@ Netchan_CopyFileFragments
qboolean Netchan_CopyFileFragments( netchan_t *chan, sizebuf_t *msg )
{
char filename[MAX_OSPATH], compressor[32];
uint uncompressedSize;
uint uncompressedSize = 0;
if( !chan->incomingready[FRAG_FILE_STREAM] )
return false;
@@ -1175,6 +1175,7 @@ qboolean Netchan_CopyFileFragments( netchan_t *chan, sizebuf_t *msg )
// copy in first chunk so we can get filename out
MSG_WriteBytes( msg, MSG_GetData( &p->frag_message ), MSG_GetNumBytesWritten( &p->frag_message ));
msg->nDataBits = msg->iCurBit; // tighten the NetMessage buffer to amount read from frag_message
MSG_Clear( msg );
Q_strncpy( filename, MSG_ReadString( msg ), sizeof( filename ));
@@ -1185,6 +1186,13 @@ qboolean Netchan_CopyFileFragments( netchan_t *chan, sizebuf_t *msg )
uncompressedSize = MSG_ReadLong( msg );
}
if( MSG_CheckOverflow( msg ))
{
Con_Printf( S_ERROR "%s: malformed file fragment header\n", __func__ );
Netchan_FlushIncoming( chan, FRAG_FILE_STREAM );
return false;
}
if( COM_StringEmptyOrNULL( filename ))
{
Con_Printf( S_ERROR "file fragment received with no filename\nFlushing input queue\n" );