Sanitize invalid particle spawner time (#15465)

This commit is contained in:
Lars Müller 2024-11-24 19:23:53 +01:00 committed by GitHub
parent 11b19cd126
commit b77ad82fb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 0 deletions

@ -270,6 +270,7 @@ ParticleSpawner::ParticleSpawner(
}
size_t max_particles = 0; // maximum number of particles likely to be visible at any given time
assert(p.time >= 0);
if (p.time != 0) {
auto maxGenerations = p.time / std::min(p.exptime.start.min, p.exptime.end.min);
max_particles = p.amount / maxGenerations;

@ -4,6 +4,7 @@
#include "client/client.h"
#include "exceptions.h"
#include "irr_v2d.h"
#include "util/base64.h"
#include "client/camera.h"
@ -1007,6 +1008,8 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
p.amount = readU16(is);
p.time = readF32(is);
if (p.time < 0)
throw SerializationError("particle spawner time < 0");
bool missing_end_values = false;
if (m_proto_ver >= 42) {

@ -3,6 +3,7 @@
// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
#include "lua_api/l_particles.h"
#include "common/c_types.h"
#include "lua_api/l_object.h"
#include "lua_api/l_internal.h"
#include "lua_api/l_particleparams.h"
@ -280,6 +281,9 @@ int ModApiParticles::l_add_particlespawner(lua_State *L)
p.node_tile = getintfield_default(L, 1, "node_tile", p.node_tile);
}
if (p.time < 0)
throw LuaError("particle spawner 'time' must be >= 0");
u32 id = getServer(L)->addParticleSpawner(p, attached, playername);
lua_pushnumber(L, id);