Skip to content

Commit 84891b5

Browse files
authored
Fix RAMFile::Open_From_Archive error handling (#789)
1 parent f11fa04 commit 84891b5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/game/common/system/ramfile.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,22 @@ bool RAMFile::Open_From_Archive(File *file, Utf8String const &name, int pos, int
278278
m_data = nullptr;
279279
}
280280

281+
if (file->Seek(pos, START) != pos) {
282+
return false;
283+
}
284+
281285
m_data = new char[size];
282286
m_size = size;
283287

284-
if (file->Seek(pos, START) != pos) {
288+
// #BUGFIX allocation check for robustness.
289+
if (m_data == nullptr) {
285290
return false;
286291
}
287292

288293
if (file->Read(m_data, m_size) != size) {
294+
// #BUGFIX clean up on failure to prevent garbage read.
295+
delete[] m_data;
296+
m_data = nullptr;
289297
return false;
290298
}
291299

0 commit comments

Comments
 (0)