From 2b5a2fa08ae8224e7117888fc7194157795305e8 Mon Sep 17 00:00:00 2001 From: Quentin Kaiser Date: Fri, 1 Dec 2023 14:01:57 +0100 Subject: [PATCH] fix(handler): improve tar handler to support sparse archives. --- tests/integration/archive/tar/__input__/sparse.tar | 3 +++ .../archive/tar/__output__/sparse.tar_extract/dummy1 | 3 +++ .../archive/tar/__output__/sparse.tar_extract/dummy2 | 3 +++ .../archive/tar/__output__/sparse.tar_extract/file1 | 3 +++ .../archive/tar/__output__/sparse.tar_extract/file2 | 3 +++ unblob/handlers/archive/tar.py | 3 +-- 6 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/integration/archive/tar/__input__/sparse.tar create mode 100644 tests/integration/archive/tar/__output__/sparse.tar_extract/dummy1 create mode 100644 tests/integration/archive/tar/__output__/sparse.tar_extract/dummy2 create mode 100644 tests/integration/archive/tar/__output__/sparse.tar_extract/file1 create mode 100644 tests/integration/archive/tar/__output__/sparse.tar_extract/file2 diff --git a/tests/integration/archive/tar/__input__/sparse.tar b/tests/integration/archive/tar/__input__/sparse.tar new file mode 100644 index 0000000000..7ae9bbecfa --- /dev/null +++ b/tests/integration/archive/tar/__input__/sparse.tar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:217eb921a851ca38185b7585a554160f2f88f76c3b123c1930468a2cc4d80e46 +size 10240 diff --git a/tests/integration/archive/tar/__output__/sparse.tar_extract/dummy1 b/tests/integration/archive/tar/__output__/sparse.tar_extract/dummy1 new file mode 100644 index 0000000000..acc63e8aa2 --- /dev/null +++ b/tests/integration/archive/tar/__output__/sparse.tar_extract/dummy1 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16fa66a7dc98d93f2a4c5d20baf5177f59c4c37fc62face65690c11c15fe6ff9 +size 51200 diff --git a/tests/integration/archive/tar/__output__/sparse.tar_extract/dummy2 b/tests/integration/archive/tar/__output__/sparse.tar_extract/dummy2 new file mode 100644 index 0000000000..acc63e8aa2 --- /dev/null +++ b/tests/integration/archive/tar/__output__/sparse.tar_extract/dummy2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16fa66a7dc98d93f2a4c5d20baf5177f59c4c37fc62face65690c11c15fe6ff9 +size 51200 diff --git a/tests/integration/archive/tar/__output__/sparse.tar_extract/file1 b/tests/integration/archive/tar/__output__/sparse.tar_extract/file1 new file mode 100644 index 0000000000..318ac0c97b --- /dev/null +++ b/tests/integration/archive/tar/__output__/sparse.tar_extract/file1 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed68b430af3630fde9b598ea74340a7be809408e493f3adff7aadbd6cfeef931 +size 45 diff --git a/tests/integration/archive/tar/__output__/sparse.tar_extract/file2 b/tests/integration/archive/tar/__output__/sparse.tar_extract/file2 new file mode 100644 index 0000000000..318ac0c97b --- /dev/null +++ b/tests/integration/archive/tar/__output__/sparse.tar_extract/file2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed68b430af3630fde9b598ea74340a7be809408e493f3adff7aadbd6cfeef931 +size 45 diff --git a/unblob/handlers/archive/tar.py b/unblob/handlers/archive/tar.py index 876b5c1a6d..a27e2c0a28 100644 --- a/unblob/handlers/archive/tar.py +++ b/unblob/handlers/archive/tar.py @@ -59,8 +59,7 @@ def _get_end_of_last_tar_entry(file) -> int: if last_member is None: return -1 - last_file_size = round_up(last_member.size, BLOCK_SIZE) - end_of_last_tar_entry = last_member.offset_data + last_file_size + end_of_last_tar_entry = tf.offset try: file.seek(end_of_last_tar_entry) except SeekError: