diff options
| author | Haoyu Qiu <timothyqiu32@gmail.com> | 2020-02-11 11:39:20 +0800 |
|---|---|---|
| committer | Haoyu Qiu <timothyqiu32@gmail.com> | 2020-02-11 17:29:25 +0800 |
| commit | 832a5c860bc5287efc0ebf19c4b2af5c5b984972 (patch) | |
| tree | b5b522f39da05cc2730e399b99b986b383ddb4b4 /core/io/file_access_compressed.cpp | |
| parent | 0b4b24883d8fe7ee3f4c7a861df0bad1d12a319c (diff) | |
| download | redot-engine-832a5c860bc5287efc0ebf19c4b2af5c5b984972.tar.gz | |
Fixes crash when resource file is corrupted
Diffstat (limited to 'core/io/file_access_compressed.cpp')
| -rw-r--r-- | core/io/file_access_compressed.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index 87ead37b91..17cc6ce58f 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -63,6 +63,10 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) { f = p_base; cmode = (Compression::Mode)f->get_32(); block_size = f->get_32(); + if (block_size == 0) { + f = NULL; // Let the caller to handle the FileAccess object if failed to open as compressed file. + ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Can't open compressed file '" + p_base->get_path() + "' with block size 0, it is corrupted."); + } read_total = f->get_32(); int bc = (read_total / block_size) + 1; int acc_ofs = f->get_position() + bc * 4; @@ -125,13 +129,11 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { char rmagic[5]; f->get_buffer((uint8_t *)rmagic, 4); rmagic[4] = 0; - if (magic != rmagic) { + if (magic != rmagic || open_after_magic(f) != OK) { memdelete(f); f = NULL; return ERR_FILE_UNRECOGNIZED; } - - open_after_magic(f); } return OK; |
