[General] Limit maximum imageData size in WorldMap packets

0.6.3
David Cernat 7 years ago
parent 9888316d8e
commit 5bb2ba1e9e

@ -59,7 +59,16 @@ void WorldstateFunctions::LoadMapTileImageFile(int cellX, int cellY, const char*
std::ifstream inputFile(filePath, std::ios::binary); std::ifstream inputFile(filePath, std::ios::binary);
mapTile.imageData = std::vector<char>(std::istreambuf_iterator<char>(inputFile), std::istreambuf_iterator<char>()); mapTile.imageData = std::vector<char>(std::istreambuf_iterator<char>(inputFile), std::istreambuf_iterator<char>());
writeWorldstate.mapChanges.mapTiles.push_back(mapTile); if (mapTile.imageData.size() > mwmp::maxImageDataSize)
{
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Error loading image file for map tile: "
"%s has a size of %i, which is over the maximum allowed of %i!",
filePath, mapTile.imageData.size(), mwmp::maxImageDataSize);
}
else
{
writeWorldstate.mapChanges.mapTiles.push_back(mapTile);
}
} }
void WorldstateFunctions::SetHour(double hour) noexcept void WorldstateFunctions::SetHour(double hour) noexcept

@ -9,6 +9,8 @@
namespace mwmp namespace mwmp
{ {
static const int maxImageDataSize = 1400;
struct MapTile struct MapTile
{ {
int x; int x;

@ -1,4 +1,5 @@
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Log.hpp>
#include "PacketWorldMap.hpp" #include "PacketWorldMap.hpp"
using namespace std; using namespace std;
@ -31,17 +32,25 @@ void PacketWorldMap::Packet(RakNet::BitStream *bs, bool send)
RW(mapTile.x, send); RW(mapTile.x, send);
RW(mapTile.y, send); RW(mapTile.y, send);
uint32_t imageDataCount; uint32_t imageDataSize;
if (send) if (send)
imageDataCount = static_cast<uint32_t>(mapTile.imageData.size()); imageDataSize = static_cast<uint32_t>(mapTile.imageData.size());
RW(imageDataCount, send); RW(imageDataSize, send);
if (imageDataSize > mwmp::maxImageDataSize)
{
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Processed invalid ID_WORLD_MAP packet where tile %i, %i had an imageDataSize of %i",
mapTile.x, mapTile.y, imageDataSize);
LOG_APPEND(Log::LOG_ERROR, "- The packet was ignored after that point");
return;
}
if (!send) if (!send)
{ {
mapTile.imageData.clear(); mapTile.imageData.clear();
mapTile.imageData.resize(imageDataCount); mapTile.imageData.resize(imageDataSize);
} }
for (auto &&imageChar : mapTile.imageData) for (auto &&imageChar : mapTile.imageData)

Loading…
Cancel
Save