Skip to content

Commit a04cb8b

Browse files
fix: 添加文件后缀判断以避免假的 zip
1 parent d2ba4a1 commit a04cb8b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

byrdocs/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ def wrapper(*args, **kwargs):
7474

7575
def get_file_type(file) -> str:
7676
# https://en.wikipedia.org/wiki/List_of_file_signatures
77-
# use magic number to check file type
77+
# use magic number to check file type, together with suffix
7878
with open(file, "rb") as f:
7979
magic_number = f.read(4)
80-
if magic_number == b"%PDF":
80+
if magic_number == b"%PDF" and file.endswith(".pdf"):
8181
return "pdf"
82-
elif magic_number == b"PK\x03\x04":
82+
elif magic_number == b"PK\x03\x04" and file.endswith(".zip"):
8383
return "zip"
8484
else:
8585
return "unsupported"

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
33
build-backend = "setuptools.build_meta"
44
[project]
55
name = "byrdocs_cli"
6-
version = "0.5.2"
6+
version = "0.5.3"
77
authors = [
88
{ name="Rikka", email="[email protected]" },
99
]

0 commit comments

Comments
 (0)