aboutsummaryrefslogtreecommitdiff
path: root/src/staticobject.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-08-19 20:14:22 +0200
committerGitHub <noreply@github.com>2021-08-19 20:14:22 +0200
commite7b05beb7d90b4ea53ef13da86ff8b8ccde1193b (patch)
treeb87dfaf74cc8443298ad0e00a0381a88ce7c5ade /src/staticobject.cpp
parent1320c51d8e15409544cba970a97b167a37513bae (diff)
downloaddragonfireclient-e7b05beb7d90b4ea53ef13da86ff8b8ccde1193b.tar.xz
Validate staticdata and object property length limits (#11511)
Some games provide users with enough freedom to create items with metadata longer than 64KB, preventing this from causing issues is on them but we'll still do the minimum not to abort the server if this happens.
Diffstat (limited to 'src/staticobject.cpp')
-rw-r--r--src/staticobject.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/staticobject.cpp b/src/staticobject.cpp
index 86e455b9f..1160ec68f 100644
--- a/src/staticobject.cpp
+++ b/src/staticobject.cpp
@@ -37,6 +37,7 @@ void StaticObject::serialize(std::ostream &os)
// data
os<<serializeString16(data);
}
+
void StaticObject::deSerialize(std::istream &is, u8 version)
{
// type
@@ -49,6 +50,29 @@ void StaticObject::deSerialize(std::istream &is, u8 version)
void StaticObjectList::serialize(std::ostream &os)
{
+ // Check for problems first
+ auto problematic = [] (StaticObject &obj) -> bool {
+ if (obj.data.size() > U16_MAX) {
+ errorstream << "StaticObjectList::serialize(): "
+ "object has excessive static data (" << obj.data.size() <<
+ "), deleting it." << std::endl;
+ return true;
+ }
+ return false;
+ };
+ for (auto it = m_stored.begin(); it != m_stored.end(); ) {
+ if (problematic(*it))
+ it = m_stored.erase(it);
+ else
+ it++;
+ }
+ for (auto it = m_active.begin(); it != m_active.end(); ) {
+ if (problematic(it->second))
+ it = m_active.erase(it);
+ else
+ it++;
+ }
+
// version
u8 version = 0;
writeU8(os, version);