diff --git a/src/pc/lua/smlua.c b/src/pc/lua/smlua.c index f98091cc3..85974e811 100644 --- a/src/pc/lua/smlua.c +++ b/src/pc/lua/smlua.c @@ -89,6 +89,7 @@ void smlua_init(void) { smlua_cobject_init_globals(); // load scripts + mod_list_size_enforce(); LOG_INFO("Loading scripts:"); struct ModTable* table = gModTableCurrent; for (int i = 0; i < table->entryCount; i++) { diff --git a/src/pc/mod_list.c b/src/pc/mod_list.c index b08eba42b..0c48c353a 100644 --- a/src/pc/mod_list.c +++ b/src/pc/mod_list.c @@ -253,6 +253,8 @@ void mod_list_update_selectable(void) { } } } + + mod_list_size_enforce(); } static void mod_list_load_local(const char* path) { @@ -295,6 +297,15 @@ static void mod_list_load_local(const char* path) { closedir(d); } +void mod_list_size_enforce(void) { + for (int i = 0; i < gModTableLocal.entryCount; i++) { + if (gModTableLocal.entries[i].size >= MAX_MOD_SIZE) { + gModTableLocal.entries[i].enabled = false; + gModTableLocal.entries[i].selectable = false; + } + } +} + void mod_list_init(void) { gModTableCurrent = &gModTableLocal; srand(time(0)); diff --git a/src/pc/mod_list.h b/src/pc/mod_list.h index d4fbbd0e5..a0eed3f1c 100644 --- a/src/pc/mod_list.h +++ b/src/pc/mod_list.h @@ -9,6 +9,7 @@ #include "src/pc/platform.h" #define MOD_PATH "./mods" +#define MAX_MOD_SIZE (2 * 1048576) // 2MB struct ModListEntry { char* name; @@ -43,6 +44,7 @@ void mod_table_clear(struct ModTable* table); void mod_list_alloc(struct ModTable* table, u16 count); void mod_list_update_selectable(void); +void mod_list_size_enforce(void); void mod_list_init(void); void mod_list_shutdown(void); diff --git a/src/pc/network/packets/packet_download.c b/src/pc/network/packets/packet_download.c index 4f82b5f5d..220c1457d 100644 --- a/src/pc/network/packets/packet_download.c +++ b/src/pc/network/packets/packet_download.c @@ -21,7 +21,6 @@ void network_send_next_download_request(void) { network_send_download_request(i, entry->remoteIndex, entry->curOffset); return; } - //LOG_INFO("sending join request"); network_send_join_request(); djui_panel_modlist_create(NULL); } @@ -134,7 +133,7 @@ void network_receive_download(struct Packet* p) { packet_read(p, &chunkSize, sizeof(u16)); packet_read(p, chunk, chunkSize * sizeof(u8)); - //LOG_ERROR("Received download %u:%llu", clientIndex, offset); + //LOG_INFO("Received download %u:%llu", clientIndex, offset); if (clientIndex >= gModTableRemote.entryCount) { LOG_ERROR("Received download of invalid index %u:%llu", clientIndex, offset); @@ -153,7 +152,7 @@ void network_receive_download(struct Packet* p) { } if ((offset + chunkSize) > entry->size) { - LOG_ERROR("Received download of invalid chunk size %u:%llu:%u", clientIndex, offset, chunkSize); + LOG_ERROR("Received download of invalid chunk size %u:%llu:%u -- %llu", clientIndex, offset, chunkSize, entry->size); return; } @@ -197,7 +196,7 @@ void network_receive_download(struct Packet* p) { entry->complete = true; } - entry->curOffset += CHUNK_SIZE * OFFSET_COUNT; + entry->curOffset += (u64)CHUNK_SIZE * OFFSET_COUNT; network_send_next_download_request(); } } diff --git a/src/pc/network/packets/packet_mod_list.c b/src/pc/network/packets/packet_mod_list.c index ebf242f84..38289893b 100644 --- a/src/pc/network/packets/packet_mod_list.c +++ b/src/pc/network/packets/packet_mod_list.c @@ -48,8 +48,8 @@ void network_send_mod_list(void) { packet_write(&p, &i, sizeof(u16)); packet_write(&p, &nameLength, sizeof(u16)); packet_write(&p, entry->name, sizeof(u8) * nameLength); - packet_write(&p, &entry->size, sizeof(u16)); - LOG_INFO(" '%s': %u", entry->name, (u16)entry->size); + packet_write(&p, &entry->size, sizeof(u64)); + LOG_INFO(" '%s': %llu", entry->name, (u64)entry->size); } network_send_to(0, &p); } @@ -107,12 +107,17 @@ void network_receive_mod_list(struct Packet* p) { char* name = (char*)calloc(nameLength + 1, sizeof(char)); packet_read(p, name, nameLength * sizeof(u8)); - u16 size = 0; - packet_read(p, &size, sizeof(u16)); + u64 size = 0; + packet_read(p, &size, sizeof(u64)); + if (size >= MAX_MOD_SIZE) { + djui_popup_create("Server had too large of a mod.\nQuitting.", 4); + network_shutdown(false); + return; + } mod_list_add_tmp(i, remoteIndex, name, size); - LOG_INFO(" '%s': %u", name, size); + LOG_INFO(" '%s': %llu", name, size); } network_send_next_download_request();