Merge pull request #66 from Excello-Recherche-Education/zip-security

Zip security
This commit is contained in:
Adrien Ufferte
2025-08-19 09:48:51 +02:00
committed by GitHub
2 changed files with 12 additions and 3 deletions
+3 -1
View File
@@ -10,6 +10,7 @@ func extract(zip_path: String, extract_path: String, extract_in_subfolder: bool
var err: Error = open(zip_path)
if err != OK:
Logger.error("FolderUnzipper: Error " + error_string(err) + " while opening file: %s" % zip_path)
close()
return ""
var extract_folder: String = extract_path.path_join(zip_path.get_file().get_basename()) if extract_in_subfolder else extract_path
@@ -30,9 +31,11 @@ func extract(zip_path: String, extract_path: String, extract_in_subfolder: bool
var error: Error = FileAccess.get_open_error()
if error != OK:
Logger.error("FolderUnzipper: Extract: Cannot open file %s. Error: %s" % [file_name, error_string(error)])
close()
return first_folder
if file == null:
Logger.error("FolderUnzipper: Extract: Cannot open file %s. File is null" % file_name)
close()
return first_folder
if file != null:
file.store_buffer(read_file(sub_path))
@@ -42,7 +45,6 @@ func extract(zip_path: String, extract_path: String, extract_in_subfolder: bool
file_copied.emit(copied_file, file_name)
close()
finished.emit()
Logger.trace("FolderUnzipper: Extraction finished in %s" % extract_folder)
return first_folder
+9 -2
View File
@@ -6,6 +6,7 @@ func write_folder_recursive(abs_path: String, rel_path: String) -> Error:
var full_path: String = abs_path.path_join(rel_path)
var dir: DirAccess = DirAccess.open(full_path)
if not dir:
close()
return DirAccess.get_open_error()
dir.list_dir_begin()
@@ -19,27 +20,32 @@ func write_folder_recursive(abs_path: String, rel_path: String) -> Error:
if dir.current_is_dir():
var error: Error = write_folder_recursive(abs_path, current_rel_path)
if error != OK:
close()
return error
else:
Logger.trace("FolderZipper: Adding %s" % current_rel_path)
var error: Error = start_file(current_rel_path)
if error != OK:
close()
return error
var file: FileAccess = FileAccess.open(current_full_path, FileAccess.READ)
error = FileAccess.get_open_error()
if error != OK:
Logger.error("FolderZipper: Extract: Cannot open file %s. Error: %s" % [current_full_path, error_string(error)])
close()
return error
if file:
write_file(file.get_buffer(file.get_length()))
file.close()
close_file()
else:
close()
return FileAccess.get_open_error() # Should never happen because error = OK
file_name = dir.get_next()
dir.list_dir_end()
close()
return OK
@@ -47,8 +53,9 @@ func compress(path: String, output_name: String) -> void:
Logger.trace("FolderZipper: Compressing %s into %s" % [path, output_name])
var err: Error = open(output_name, ZIPPacker.APPEND_CREATE)
if err != OK:
Logger.error("FolderZipper: Error " + error_string(err) + " while opening archive: %s" % output_name)
return
Logger.error("FolderZipper: Error " + error_string(err) + " while opening archive: %s" % output_name)
close()
return
path = path.simplify_path()
err = write_folder_recursive(path.get_base_dir(), path.get_file())
if err != OK: