Merge remote-tracking branch 'itsRevela/main'
# Conflicts: # .github/workflows/nightly.yml # .gitignore # Minecraft.Client/ChatScreen.cpp # Minecraft.Client/ClientConnection.cpp # Minecraft.Client/Common/Audio/SoundEngine.cpp # Minecraft.Client/Common/Audio/SoundEngine.h # Minecraft.Client/Common/Media/MediaWindows64.arc # Minecraft.Client/Common/UI/IUIScene_HUD.cpp # Minecraft.Client/Common/UI/UIControl_Base.cpp # Minecraft.Client/Common/UI/UIScene_DeathMenu.cpp # Minecraft.Client/Common/UI/UIScene_JoinMenu.cpp # Minecraft.Client/Common/XUI/XUI_Chat.cpp # Minecraft.Client/Common/XUI/XUI_Death.cpp # Minecraft.Client/Font.cpp # Minecraft.Client/Gui.cpp # Minecraft.Client/PendingConnection.cpp # Minecraft.Client/PlayerConnection.cpp # Minecraft.Client/PlayerConnection.h # Minecraft.Client/PlayerList.cpp # Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp # Minecraft.Client/Windows64/Network/WinsockNetLayer.h # Minecraft.Client/Windows64Media/strings.h # Minecraft.Client/cmake/sources/Common.cmake # Minecraft.Server/Console/ServerCliEngine.cpp # Minecraft.Server/Console/commands/whitelist/CliCommandWhitelist.cpp # Minecraft.Server/Windows64/ServerMain.cpp # Minecraft.World/WitherBoss.h # Minecraft.World/cmake/sources/Common.cmake # README.md
This commit is contained in:
@@ -401,20 +401,32 @@ void Packet::writeUtf(const wstring& value, DataOutputStream *dos) // throws IOE
|
||||
|
||||
wstring Packet::readUtf(DataInputStream *dis, int maxLength) // throws IOException TODO 4J JEV, should this declare a throws?
|
||||
{
|
||||
// Global safety cap to prevent memory exhaustion from malicious string lengths
|
||||
static const int kMaxGlobalStringLength = 8192;
|
||||
if (maxLength > kMaxGlobalStringLength)
|
||||
{
|
||||
maxLength = kMaxGlobalStringLength;
|
||||
}
|
||||
|
||||
short stringLength = dis->readShort();
|
||||
if (stringLength > maxLength || stringLength <= 0)
|
||||
if (stringLength <= 0)
|
||||
{
|
||||
return L"";
|
||||
// throw new IOException( stream.str() );
|
||||
if (stringLength < 0)
|
||||
{
|
||||
app.DebugPrintf("SECURITY: readUtf received negative string length %d\n", stringLength);
|
||||
}
|
||||
return L"";
|
||||
}
|
||||
if (stringLength < 0)
|
||||
if (stringLength > maxLength)
|
||||
{
|
||||
assert(false);
|
||||
// throw new IOException(L"Received string length is less than zero! Weird string!");
|
||||
app.DebugPrintf("SECURITY: readUtf received string length %d exceeding max %d\n", stringLength, maxLength);
|
||||
// Consume the declared bytes to keep the stream synchronized
|
||||
dis->skip(static_cast<int64_t>(stringLength) * 2);
|
||||
return L"";
|
||||
}
|
||||
|
||||
wstring builder = L"";
|
||||
builder.reserve(stringLength);
|
||||
for (int i = 0; i < stringLength; i++)
|
||||
{
|
||||
wchar_t rc = dis->readChar();
|
||||
|
||||
Reference in New Issue
Block a user