Skip to content

Fix path traversal in tar/zip extraction#4176

Open
AAtomical wants to merge 1 commit into
PaddlePaddle:developfrom
AAtomical:fix/tarslip-path-traversal
Open

Fix path traversal in tar/zip extraction#4176
AAtomical wants to merge 1 commit into
PaddlePaddle:developfrom
AAtomical:fix/tarslip-path-traversal

Conversation

@AAtomical

Copy link
Copy Markdown

Summary

_uncompress_file_tar() and _uncompress_file_zip() in paddlespeech/cli/download.py extract archive members using tarfile.extract() / zipfile.extract() with no path validation. A crafted archive containing ../ entries can write files outside the intended extraction directory.

This is especially relevant because dataset download URLs use plaintext HTTP (http://www.openslr.org/, http://openslr.elda.org/), making MITM injection of malicious archives feasible.

Changes

  • Validate all member names before extraction in both _uncompress_file_tar() and _uncompress_file_zip()
  • Reject members with absolute paths or .. path components

Test

import io, tarfile, tempfile
from pathlib import Path
from paddlespeech.cli.download import _uncompress_file_tar

tar_path = Path(tempfile.mkdtemp()) / "test.tar.gz"
with tarfile.open(str(tar_path), "w:gz") as tf:
    info = tarfile.TarInfo(name="../../../tmp/proof.txt")
    data = b"traversal\n"
    info.size = len(data)
    tf.addfile(info, io.BytesIO(data))

try:
    _uncompress_file_tar(str(tar_path))
    print("FAIL: no exception raised")
except ValueError as e:
    print(f"PASS: {e}")

Before fix: file written to /tmp/proof.txt
After fix: ValueError: Path traversal detected in tar member: ../../../tmp/proof.txt

Validate archive member names before extraction to prevent
directory traversal via crafted ../  entries.
@paddle-bot

paddle-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

Thanks for your contribution!

@mergify mergify Bot added the CLI label Jul 18, 2026
@AAtomical

AAtomical commented Jul 18, 2026

Copy link
Copy Markdown
Author

Fix #4175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant