From 7d24908959670339bfad9959af1bf706da102540 Mon Sep 17 00:00:00 2001 From: Nikolay Bogoychev Date: Wed, 18 Jan 2023 16:46:07 +0000 Subject: [PATCH] Apply security update and formatting --- .github/workflows/build.yml | 2 +- .github/workflows/coding-styles.yml | 6 +++--- 3rd_party/ssplit-cpp | 2 +- bindings/python/repository.py | 21 ++++++++++++++++++++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 25305a1..2cac911 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -352,7 +352,7 @@ jobs: python3 -m pip install black isort pytype - name: "Formatting checks: black, isort" run: | - python3 -m black --check bindings/python/ setup.py doc/conf.py + python3 -m black --diff --check bindings/python/ setup.py doc/conf.py python3 -m isort --profile black --diff --check bindings/python setup.py doc/conf.py - name: "Static typing checks: pytype" run: |- diff --git a/.github/workflows/coding-styles.yml b/.github/workflows/coding-styles.yml index e666c51..b133456 100644 --- a/.github/workflows/coding-styles.yml +++ b/.github/workflows/coding-styles.yml @@ -1,6 +1,6 @@ name: "Coding Style" -on: +on: push: branches: [ main, ci-sandbox ] pull_request: @@ -18,7 +18,7 @@ jobs: - name: Install dependencies run: | - sudo apt-get update + sudo apt-get update sudo apt-get install -y build-essential cmake sudo apt-get install -y clang-format clang-tidy @@ -30,7 +30,7 @@ jobs: - name: Prepare build, compilation database etc. run: | mkdir -p build - cd build + cd build cmake \ -DUSE_WASM_COMPATIBLE_SOURCE=off -DCMAKE_EXPORT_COMPILE_COMMANDS=on \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ diff --git a/3rd_party/ssplit-cpp b/3rd_party/ssplit-cpp index 8bc2f35..ad2c5a5 160000 --- a/3rd_party/ssplit-cpp +++ b/3rd_party/ssplit-cpp @@ -1 +1 @@ -Subproject commit 8bc2f35b64f1012b8c31087610ab42f67aa70154 +Subproject commit ad2c5a52a507ec5a1f58c6403fc674e76e92e185 diff --git a/bindings/python/repository.py b/bindings/python/repository.py index a8e4a79..323b448 100644 --- a/bindings/python/repository.py +++ b/bindings/python/repository.py @@ -137,7 +137,26 @@ class TranslateLocallyLike(Repository): download_resource(model["url"], save_location) with tarfile.open(save_location) as model_archive: - model_archive.extractall(self.dirs["models"]) + + def is_within_directory(directory, target): + + abs_directory = os.path.abspath(directory) + abs_target = os.path.abspath(target) + + prefix = os.path.commonprefix([abs_directory, abs_target]) + + return prefix == abs_directory + + def safe_extract(tar, path=".", members=None, *, numeric_owner=False): + + for member in tar.getmembers(): + member_path = os.path.join(path, member.name) + if not is_within_directory(path, member_path): + raise Exception("Attempted Path Traversal in Tar File") + + tar.extractall(path, members, numeric_owner=numeric_owner) + + safe_extract(model_archive, self.dirs["models"]) fprefix = self._archive_name_without_extension(model["url"]) model_dir = os.path.join(self.dirs["models"], fprefix) symlink = os.path.join(self.dirs["models"], model["code"])