mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 09:06:55 -04:00
Properly prevent loading multiplayer maps over 2 GB in size
This commit is contained in:
parent
0c21f86a62
commit
bcd6e6e457
@ -1061,8 +1061,7 @@ static void GenLevelScreen_Gen(void* screen, const struct MapGenerator* gen) {
|
||||
int length = GenLevelScreen_GetInt(s, 2);
|
||||
int seed = GenLevelScreen_GetSeedInt(s, 3);
|
||||
|
||||
cc_uint64 volume = (cc_uint64)width * height * length;
|
||||
if (volume > Int32_MaxValue) {
|
||||
if (!World_CheckVolume(width, height, length)) {
|
||||
Chat_AddRaw("&cThe generated map's volume is too big.");
|
||||
} else if (!width || !height || !length) {
|
||||
Chat_AddRaw("&cOne of the map dimensions is invalid.");
|
||||
|
@ -627,6 +627,10 @@ static void Classic_LevelFinalise(cc_uint8* data) {
|
||||
Chat_AddRaw("&cFailed to load map, try joining a different map");
|
||||
Chat_Add2( " &cBlocks array size (%i) does not match volume of map (%i)", &map_volume, &volume);
|
||||
FreeMapStates();
|
||||
} else if (!World_CheckVolume(width, height, length)) {
|
||||
Chat_AddRaw("&cFailed to load map, try joining a different map");
|
||||
Chat_AddRaw(" &cAttempted to load map over 2 GB in size");
|
||||
FreeMapStates();
|
||||
}
|
||||
|
||||
#ifdef EXTENDED_BLOCKS
|
||||
|
@ -2217,7 +2217,6 @@ static int TextGroupWidget_Reduce(struct TextGroupWidget* w, char* chars, int ta
|
||||
}
|
||||
|
||||
static void TextGroupWidget_RemoveColorPrefix(cc_string* text, int i) {
|
||||
/* Delete leading colour code if present */
|
||||
if (i + 2 > text->length || text->buffer[i] != '&') return;
|
||||
if (!Drawer2D_ValidColorCodeAt(text, i + 1)) return;
|
||||
|
||||
|
@ -115,6 +115,11 @@ static CC_INLINE cc_bool World_ContainsXZ(int x, int z) {
|
||||
&& (unsigned)z < (unsigned)World.Length;
|
||||
}
|
||||
|
||||
static CC_INLINE cc_bool World_CheckVolume(int width, int height, int length) {
|
||||
cc_uint64 volume = (cc_uint64)width * height * length;
|
||||
return volume <= Int32_MaxValue;
|
||||
}
|
||||
|
||||
enum EnvVar {
|
||||
ENV_VAR_EDGE_BLOCK, ENV_VAR_SIDES_BLOCK, ENV_VAR_EDGE_HEIGHT, ENV_VAR_SIDES_OFFSET,
|
||||
ENV_VAR_CLOUDS_HEIGHT, ENV_VAR_CLOUDS_SPEED, ENV_VAR_WEATHER_SPEED, ENV_VAR_WEATHER_FADE,
|
||||
|
Loading…
x
Reference in New Issue
Block a user