summaryrefslogtreecommitdiffstats
path: root/modules/zip/zip_packer.cpp
diff options
context:
space:
mode:
authorMack <86566939+Macksaur@users.noreply.github.com>2022-12-06 17:40:46 +0000
committerMack <86566939+Macksaur@users.noreply.github.com>2023-05-31 13:11:59 +0000
commit1326b7e04f6592195d3bc377ec602fd2e120a336 (patch)
tree63183cdd45397def7a7e3803820a81babf50dbf5 /modules/zip/zip_packer.cpp
parent83d5cbf519c3864fe793a84ed6ae0f74a0f91660 (diff)
downloadredot-engine-1326b7e04f6592195d3bc377ec602fd2e120a336.tar.gz
Fix buffer over-read and memory leaks when using long filepaths in a zip archive and improved robustness of long filepaths and reading files.
Diffstat (limited to 'modules/zip/zip_packer.cpp')
-rw-r--r--modules/zip/zip_packer.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/modules/zip/zip_packer.cpp b/modules/zip/zip_packer.cpp
index 65f451a3f9..c8b4fb4e77 100644
--- a/modules/zip/zip_packer.cpp
+++ b/modules/zip/zip_packer.cpp
@@ -39,17 +39,19 @@ Error ZIPPacker::open(String p_path, ZipAppend p_append) {
}
zlib_filefunc_def io = zipio_create_io(&fa);
- zf = zipOpen2(p_path.utf8().get_data(), p_append, NULL, &io);
- return zf != NULL ? OK : FAILED;
+ zf = zipOpen2(p_path.utf8().get_data(), p_append, nullptr, &io);
+ return zf != nullptr ? OK : FAILED;
}
Error ZIPPacker::close() {
ERR_FAIL_COND_V_MSG(fa.is_null(), FAILED, "ZIPPacker cannot be closed because it is not open.");
- Error err = zipClose(zf, NULL) == ZIP_OK ? OK : FAILED;
+ Error err = zipClose(zf, nullptr) == ZIP_OK ? OK : FAILED;
if (err == OK) {
- zf = NULL;
+ DEV_ASSERT(fa == nullptr);
+ zf = nullptr;
}
+
return err;
}
@@ -60,18 +62,18 @@ Error ZIPPacker::start_file(String p_path) {
OS::DateTime time = OS::get_singleton()->get_datetime();
+ zipfi.tmz_date.tm_sec = time.second;
+ zipfi.tmz_date.tm_min = time.minute;
zipfi.tmz_date.tm_hour = time.hour;
zipfi.tmz_date.tm_mday = time.day;
- zipfi.tmz_date.tm_min = time.minute;
zipfi.tmz_date.tm_mon = time.month - 1;
- zipfi.tmz_date.tm_sec = time.second;
zipfi.tmz_date.tm_year = time.year;
zipfi.dosDate = 0;
- zipfi.external_fa = 0;
zipfi.internal_fa = 0;
+ zipfi.external_fa = 0;
- int ret = zipOpenNewFileInZip(zf, p_path.utf8().get_data(), &zipfi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION);
- return ret == ZIP_OK ? OK : FAILED;
+ int err = zipOpenNewFileInZip(zf, p_path.utf8().get_data(), &zipfi, nullptr, 0, nullptr, 0, nullptr, Z_DEFLATED, Z_DEFAULT_COMPRESSION);
+ return err == ZIP_OK ? OK : FAILED;
}
Error ZIPPacker::write_file(Vector<uint8_t> p_data) {