Fix ZIPReader.get_files() error on empty zip files

Added check for empty zip file before trying to look at first file

Fixes #90388

(cherry picked from commit 2dad2fbce2)
This commit is contained in:
aaronp64 2024-04-08 15:57:35 -04:00 committed by Rémi Verschelde
parent 3c1be8d067
commit 6710381d9a
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 8 additions and 1 deletions

View File

@ -58,7 +58,14 @@ Error ZIPReader::close() {
PackedStringArray ZIPReader::get_files() { PackedStringArray ZIPReader::get_files() {
ERR_FAIL_COND_V_MSG(fa.is_null(), PackedStringArray(), "ZIPReader must be opened before use."); ERR_FAIL_COND_V_MSG(fa.is_null(), PackedStringArray(), "ZIPReader must be opened before use.");
int err = unzGoToFirstFile(uzf); unz_global_info gi;
int err = unzGetGlobalInfo(uzf, &gi);
ERR_FAIL_COND_V(err != UNZ_OK, PackedStringArray());
if (gi.number_entry == 0) {
return PackedStringArray();
}
err = unzGoToFirstFile(uzf);
ERR_FAIL_COND_V(err != UNZ_OK, PackedStringArray()); ERR_FAIL_COND_V(err != UNZ_OK, PackedStringArray());
List<String> s; List<String> s;