diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-02-11 21:35:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-11 21:35:03 +0100 |
commit | 948d95897c58d1940e3f76fa033d446def294637 (patch) | |
tree | 938cdcbdf43f967ef0236219d02b25ffcd240aa3 /core/io/file_access_compressed.cpp | |
parent | 2d637e38106556f44c2ed251075ef6bcfecad7c7 (diff) | |
parent | 832a5c860bc5287efc0ebf19c4b2af5c5b984972 (diff) |
Merge pull request #36095 from timothyqiu/corrupted-resource
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; |