Muhamed-Kheir commited on
Commit
fc7f0d3
·
verified ·
1 Parent(s): 137d7d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py CHANGED
@@ -24,6 +24,23 @@ def _zip_dir(folder: str, zip_path: str) -> None:
24
  rel = os.path.relpath(full, folder)
25
  z.write(full, rel)
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  def run_prediction(unknown_files, kmer_zip, seqtype, mode, identity, coverage, fdr):
29
  if not unknown_files:
 
24
  rel = os.path.relpath(full, folder)
25
  z.write(full, rel)
26
 
27
+ def _safe_extract_zip(zip_path: str, dst_dir: str) -> None:
28
+ """Safely extract FASTA files from ZIP (prevents zip-slip)."""
29
+ with zipfile.ZipFile(zip_path, "r") as z:
30
+ for member in z.infolist():
31
+ if member.is_dir():
32
+ continue
33
+
34
+ target = os.path.normpath(os.path.join(dst_dir, member.filename))
35
+ if not target.startswith(os.path.abspath(dst_dir) + os.sep):
36
+ continue
37
+
38
+ if not member.filename.lower().endswith((".fa", ".fasta", ".fas", ".fna")):
39
+ continue
40
+
41
+ os.makedirs(os.path.dirname(target), exist_ok=True)
42
+ with z.open(member) as src, open(target, "wb") as out:
43
+ shutil.copyfileobj(src, out)
44
 
45
  def run_prediction(unknown_files, kmer_zip, seqtype, mode, identity, coverage, fdr):
46
  if not unknown_files: