Skip to content

Commit 7540d03

Browse files
authored
fix!: windows needs python3.12 for tarfile support (#4001)
BREAKING CHANGE: windows users must use python 3.12 if they want tarfile support I have been unable to find a sufficiently good safe tar workaround on windows when python < 3.12, so I'm disabling support. - Windows users will get an error message asking them to install python 3.12 if they try to extract a tarfile - Since most of our tests use tar files, there is no point in running tests on windows on older versions of python. I have changed windows_longtests to use python 3.12 and have disabled testing on other versions of python for windows (linux tests remain unchanged) - Effectively this means we only support windows users using python 3.12 going forwards, although we aren't going to stop users from trying to use it. If you're not scanning tarfiles, things will probably still work, we just don't have a way to test reliably. I don't like this solution, but I haven't been able to find a better workaround. Help is very much welcome if anyone's got a better idea of how to handle this. Signed-off-by: Terri Oda <[email protected]>
1 parent 09c5af4 commit 7540d03

File tree

2 files changed

+15
-83
lines changed

2 files changed

+15
-83
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -377,84 +377,6 @@ jobs:
377377
pytest -v
378378
test/test_json.py
379379
380-
windows_tests:
381-
name: Windows tests
382-
if: |
383-
! github.event.pull_request.user.login == 'github-actions[bot]' ||
384-
! (
385-
startsWith(github.head_ref, 'chore-sbom-py') ||
386-
contains(
387-
fromJSON('["chore-update-table","chore-precommit-config","chore-spdx-header"]'),
388-
github.head_ref
389-
)
390-
)
391-
runs-on: windows-latest
392-
timeout-minutes: 90
393-
env:
394-
NO_EXIT_CVE_NUM: 1
395-
PYTHONIOENCODING: 'utf8'
396-
steps:
397-
- name: Harden Runner
398-
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
399-
with:
400-
egress-policy: audit
401-
402-
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
403-
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
404-
with:
405-
python-version: '3.10'
406-
cache: 'pip'
407-
- name: Get date
408-
id: get-date
409-
run: |
410-
echo "DATE=$(get-date -format "yyyyMMdd")" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
411-
echo "YESTERDAY=$(get-date (get-date).addDays(-1) -format "yyyyMMdd")" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
412-
- name: Print Cache Keys
413-
run: |
414-
echo "Today's Cache Key: Linux-cve-bin-tool-${{ steps.get-date.outputs.DATE }}"
415-
echo "Yesterday's Cache Key: Linux-cve-bin-tool-${{ steps.get-date.outputs.YESTERDAY }}"
416-
- name: Get today's cached database
417-
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
418-
id: todays-cache
419-
with:
420-
path: cache
421-
key: Linux-cve-bin-tool-${{ steps.get-date.outputs.DATE }}
422-
enableCrossOsArchive: true
423-
- name: Get yesterday's cached database if today's is not available
424-
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
425-
if: steps.todays-cache.outputs.cache-hit != 'true'
426-
with:
427-
path: cache
428-
key: Linux-cve-bin-tool-${{ steps.get-date.outputs.YESTERDAY }}
429-
enableCrossOsArchive: true
430-
- name: Move cache to ~/.cache/cve-bin-tool
431-
run: |
432-
mkdir '~\.cache'
433-
if (Test-Path -Path cache) { mv cache '~\.cache\cve-bin-tool' }
434-
- name: Install cve-bin-tool
435-
run: |
436-
python -m pip install --upgrade pip
437-
python -m pip install --upgrade setuptools
438-
python -m pip install --upgrade wheel
439-
python -m pip install --upgrade -r dev-requirements.txt
440-
python -m pip install --upgrade .
441-
- name: Try single CLI run of tool
442-
run: |
443-
python -m cve_bin_tool.cli test/assets/test-kerberos-5-1.15.1.out
444-
- name: Run async tests
445-
run: >
446-
pytest -n 4 -v
447-
--ignore=test/test_cli.py
448-
--ignore=test/test_cvedb.py
449-
--ignore=test/test_requirements.py
450-
--ignore=test/test_html.py
451-
--ignore=test/test_json.py
452-
- name: Run synchronous tests
453-
run: >
454-
pytest -v
455-
test/test_cli.py
456-
test/test_cvedb.py
457-
458380
windows_long_tests:
459381
name: Windows long tests
460382
if: |
@@ -481,7 +403,7 @@ jobs:
481403
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
482404
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
483405
with:
484-
python-version: '3.9'
406+
python-version: '3.12'
485407
cache: 'pip'
486408
- name: Get date
487409
id: get-date

cve_bin_tool/extractor.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@
3030
run_coroutine,
3131
)
3232

33-
from .error_handler import ErrorHandler, ErrorMode, ExtractionFailed, UnknownArchiveType
33+
from .error_handler import (
34+
ErrorHandler,
35+
ErrorMode,
36+
ExtractionFailed,
37+
ExtractionToolNotFound,
38+
UnknownArchiveType,
39+
)
3440
from .log import LOGGER
3541

3642
# Run rpmfile in a thread
@@ -139,9 +145,13 @@ async def extract_file_tar(self, filename, extraction_path):
139145
# nosec line because bandit doesn't understand filters yet
140146

141147
elif sys.platform == "win32":
142-
# use unsafe extraction for now, fix will come in separate PR
143-
with tarfile.open(filename) as tar:
144-
tar.extractall(path=extraction_path) # nosec - fix in progress
148+
# Windows users must use python 3.12 or later because the
149+
# workaround below fails on windows
150+
# Patches welcome if you can fix this!
151+
self.logger.error(
152+
"Install python 3.12 or later to support tarfile extraction"
153+
)
154+
return ExtractionToolNotFound
145155

146156
# Some versions may need us to implement a filter to avoid unsafe behaviour
147157
# we could consider logging a warning here

0 commit comments

Comments
 (0)