Commit 790252e6 authored by Chen Bill's avatar Chen Bill Committed by GitHub

check sizeof deckBuffer in LoadDeck (#2564)

* Revert "fix"

This reverts commit 51aa8940.

* check sizeof deckBuffer in LoadDeck

* clear current_deck when selecting a wrong file
parent bb82764e
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netdb.h> #include <netdb.h>
#include <unistd.h> #include <unistd.h>
#include <locale.h>
#define SD_BOTH 2 #define SD_BOTH 2
#define SOCKET int #define SOCKET int
......
...@@ -242,6 +242,8 @@ bool DeckManager::LoadDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUICom ...@@ -242,6 +242,8 @@ bool DeckManager::LoadDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUICom
bool res = LoadDeck(filepath, is_packlist); bool res = LoadDeck(filepath, is_packlist);
if(res && mainGame->is_building) if(res && mainGame->is_building)
mainGame->deckBuilder.RefreshPackListScroll(); mainGame->deckBuilder.RefreshPackListScroll();
if (!res)
current_deck.clear();
return res; return res;
} }
FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) { FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
...@@ -280,8 +282,8 @@ bool DeckManager::LoadDeck(const wchar_t* file, bool is_packlist) { ...@@ -280,8 +282,8 @@ bool DeckManager::LoadDeck(const wchar_t* file, bool is_packlist) {
} }
if(!reader) if(!reader)
return false; return false;
size_t size = reader->getSize(); auto size = reader->getSize();
if(size >= 0x20000) { if(size >= (int)sizeof deckBuffer) {
reader->drop(); reader->drop();
return false; return false;
} }
...@@ -296,7 +298,7 @@ bool DeckManager::LoadDeck(std::istringstream* deckStream, bool is_packlist) { ...@@ -296,7 +298,7 @@ bool DeckManager::LoadDeck(std::istringstream* deckStream, bool is_packlist) {
int cardlist[300]; int cardlist[300];
bool is_side = false; bool is_side = false;
std::string linebuf; std::string linebuf;
while(std::getline(*deckStream, linebuf) && ct < 300) { while(std::getline(*deckStream, linebuf, '\n') && ct < 300) {
if(linebuf[0] == '!') { if(linebuf[0] == '!') {
is_side = true; is_side = true;
continue; continue;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "game.h" #include "game.h"
#include "data_manager.h" #include "data_manager.h"
#include <event2/thread.h> #include <event2/thread.h>
#include <locale.h>
#include <memory> #include <memory>
#ifdef __APPLE__ #ifdef __APPLE__
#import <CoreFoundation/CoreFoundation.h> #import <CoreFoundation/CoreFoundation.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment