1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-15 20:03:15 +02:00

Fixed buffer overrun.

This commit is contained in:
Frank Zago
2009-08-02 15:18:35 +00:00
parent 048ab62530
commit 2496cb4aa5
2 changed files with 19 additions and 25 deletions

View File

@@ -233,7 +233,7 @@ void CLodHandler::extract(std::string FName)
for (int i=0;i<totalFiles;i++) for (int i=0;i<totalFiles;i++)
{ {
fseek(FLOD, entries[i].offset, 0); fseek(FLOD, entries[i].offset, 0);
std::string bufff = (DATA_DIR + FName.substr(0, FName.size()-4) + PATHSEPARATOR + (char*)entries[i].name); std::string bufff = (DATA_DIR + FName.substr(0, FName.size()-4) + PATHSEPARATOR + entries[i].nameStr);
unsigned char * outp; unsigned char * outp;
if (entries[i].size==0) //file is not compressed if (entries[i].size==0) //file is not compressed
{ {
@@ -279,7 +279,7 @@ void CLodHandler::extractFile(std::string FName, std::string name)
std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper); std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper);
for (int i=0;i<totalFiles;i++) for (int i=0;i<totalFiles;i++)
{ {
std::string buf1 = std::string((char*)entries[i].name); std::string buf1 = entries[i].nameStr;
std::transform(buf1.begin(), buf1.end(), buf1.begin(), (int(*)(int))toupper); std::transform(buf1.begin(), buf1.end(), buf1.begin(), (int(*)(int))toupper);
if(buf1!=name) if(buf1!=name)
continue; continue;
@@ -359,35 +359,30 @@ void CLodHandler::init(std::string lodFile, std::string dirName)
{ {
Entry entry; Entry entry;
char bufc = -1; char bufc = -1;
bool appending = true; bool valid = true;
for(int kk=0; kk<12; ++kk)
entry.nameStr = "";
// Read name
for(int kk=0; kk<16; ++kk)
{ {
//FLOD.read(bufc, 1);
fread(&bufc, 1, 1, FLOD); fread(&bufc, 1, 1, FLOD);
if(appending) if (valid) {
{ if (bufc)
entry.name[kk] = toupper(bufc); entry.nameStr+=toupper(bufc);
} else
else valid = false;
{
entry.name[kk] = 0;
appending = false;
} }
} }
fread((char*)entry.hlam_1, 1, 4, FLOD);
fread((char*)temp, 1, 4, FLOD); fread((char*)temp, 1, 4, FLOD);
entry.offset=readNormalNr(temp,4); entry.offset=readNormalNr(temp,4);
fread((char*)temp, 1, 4, FLOD); fread((char*)temp, 1, 4, FLOD);
entry.realSize=readNormalNr(temp,4); entry.realSize=readNormalNr(temp,4);
fread((char*)entry.hlam_2, 1, 4, FLOD); fread((char*)temp, 1, 4, FLOD);
fread((char*)temp, 1, 4, FLOD); fread((char*)temp, 1, 4, FLOD);
entry.size=readNormalNr(temp,4); entry.size=readNormalNr(temp,4);
for (int z=0;z<12;z++)
{
if (entry.name[z])
entry.nameStr+=entry.name[z];
else break;
}
entries.push_back(entry); entries.push_back(entry);
} }
boost::filesystem::directory_iterator enddir; boost::filesystem::directory_iterator enddir;
@@ -444,4 +439,4 @@ CLodHandler::CLodHandler()
CLodHandler::~CLodHandler() CLodHandler::~CLodHandler()
{ {
delete mutex; delete mutex;
} }

View File

@@ -30,13 +30,12 @@ namespace NLoadHandlerHelp
struct Entry struct Entry
{ {
unsigned char name[12], //filename // Info extracted from LOD file
hlam_1[4], //???
hlam_2[4]; //probably type of file
std::string nameStr; std::string nameStr;
int offset, //from beginning int offset, //from beginning
realSize, //size without compression realSize, //size without compression
size; //and with size; //and with
bool operator<(const std::string & comp) const bool operator<(const std::string & comp) const
{ {
return nameStr<comp; return nameStr<comp;