mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Prevent VoxelManipulator size overflow
This commit is contained in:
parent
2cdf3af1b8
commit
9dd09d1056
4 changed files with 33 additions and 31 deletions
|
@ -113,6 +113,20 @@ void VoxelManipulator::print(std::ostream &o, const NodeDefManager *ndef,
|
|||
}
|
||||
}
|
||||
|
||||
static inline void checkArea(const VoxelArea &a)
|
||||
{
|
||||
// won't overflow since cbrt(2^64) > 2^16
|
||||
u64 real_volume = static_cast<u64>(a.getExtent().X) * a.getExtent().Y * a.getExtent().Z;
|
||||
|
||||
// Volume limit equal to 8 default mapchunks, (80 * 2) ^ 3 = 4,096,000
|
||||
// Note: the hard limit is somewhere around 2^31 due to s32 type
|
||||
constexpr u64 MAX_ALLOWED = 4096000;
|
||||
if (real_volume > MAX_ALLOWED) {
|
||||
throw BaseException("VoxelManipulator: "
|
||||
"Area volume exceeds allowed value of " + std::to_string(MAX_ALLOWED));
|
||||
}
|
||||
}
|
||||
|
||||
void VoxelManipulator::addArea(const VoxelArea &area)
|
||||
{
|
||||
// Cancel if requested area has zero volume
|
||||
|
@ -124,18 +138,10 @@ void VoxelManipulator::addArea(const VoxelArea &area)
|
|||
return;
|
||||
|
||||
// Calculate new area
|
||||
VoxelArea new_area;
|
||||
// New area is the requested area if m_area has zero volume
|
||||
if(m_area.hasEmptyExtent())
|
||||
{
|
||||
new_area = area;
|
||||
}
|
||||
// Else add requested area to m_area
|
||||
else
|
||||
{
|
||||
new_area = m_area;
|
||||
new_area.addArea(area);
|
||||
}
|
||||
VoxelArea new_area = m_area;
|
||||
new_area.addArea(area);
|
||||
|
||||
checkArea(new_area);
|
||||
|
||||
u32 new_size = new_area.getVolume();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue