Skip to content

Commit 5d9fd6d

Browse files
authored
Merge pull request #565 from onekey-sec/563-tar-filename-too-long
fix(handlers): fix edge cases in tar handler (empty name, too long name).
2 parents 5c886cc + 0dec6be commit 5d9fd6d

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:8b5233dfb3a4a23a3bf291bfff8ccfb371fbb2136cb093247d30af090d1e4276
3+
size 10240
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:bd002ebcec73917b4294602e2999809e4119f5209a74f92fc0f70bff838bca69
3+
size 10240
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:303980bcb9e9e6cdec515230791af8b0ab1aaa244b58a8d99152673aa22197d0
3+
size 6
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:303980bcb9e9e6cdec515230791af8b0ab1aaa244b58a8d99152673aa22197d0
3+
size 6

unblob/handlers/archive/_safe_tarfile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
logger = get_logger()
1010

1111
RUNNING_AS_ROOT = os.getuid() == 0
12+
MAX_PATH_LEN = 255
1213

1314

1415
class SafeTarFile(TarFile):
@@ -18,6 +19,14 @@ def extract(
1819
path_as_path = Path(str(path))
1920
member_name_path = Path(str(member.name))
2021

22+
if not member.name:
23+
logger.warning("File with empty filename in tar archive. Skipping")
24+
return
25+
26+
if len(member.name) > MAX_PATH_LEN:
27+
logger.warning("File with filename too long in tar archive. Skipping")
28+
return
29+
2130
if not RUNNING_AS_ROOT and (member.ischr() or member.isblk()):
2231
logger.warning(
2332
"missing elevated permissions, skipping block and character device creation",

0 commit comments

Comments
 (0)