Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Server/mods/deathmatch/logic/packets/CVoiceDataPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ bool CVoiceDataPacket::Read(NetBitStreamInterface& BitStream)

if (BitStream.Read(voiceBufferLength) && voiceBufferLength <= m_voiceBuffer.capacity())
{
if (!BitStream.CanReadNumberOfBytes(voiceBufferLength))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is actually unnecessary and essentially redundant. The logic drops invalid packets in
if (BitStream.Read(voiceBufferLength) && voiceBufferLength <= m_voiceBuffer.capacity())

Copy link
Copy Markdown
Author

@G-Moris G-Moris Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it handle a scheme like this?

Write(2048);
Write("", 0);

I doubt it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does. If you attempt to read more from the BitStream than is available, it simply returns false.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does. If you attempt to read more from the BitStream than is available, it simply returns false.

Calling resize is more expensive than performing a single check.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you call resize when the buffer is already that size, it doesn't consume significant CPU time, as no reallocations occur..

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you call resize when the buffer is already that size, it doesn't consume significant CPU time, as no reallocations occur..

If you're that confident about it - good.

return false;

m_voiceBuffer.resize(voiceBufferLength);
return BitStream.Read(reinterpret_cast<char*>(m_voiceBuffer.data()), m_voiceBuffer.size());
}
Expand Down
Loading