diff --git a/README.md b/README.md
index b3ff9d8..047c443 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,6 @@
+
+
+
# Learn Python Programming 3rd Edition
Welcome to Learn Python Programming, 3rd Edition.
@@ -62,3 +65,7 @@ find all the instructions you need in the chapter's text.
**Note**:
Always remember to activate the virtual environment before you install
third-party libraries.
+### Download a free PDF
+
+ If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.
+
https://packt.link/free-ebook/9781801815093
\ No newline at end of file
diff --git a/ch08/files/compression/tar.py b/ch08/files/compression/tar.py
index 69af6c2..593c0fc 100644
--- a/ch08/files/compression/tar.py
+++ b/ch08/files/compression/tar.py
@@ -8,4 +8,26 @@
tar.add('subfolder/content4.txt')
with tarfile.open('example.tar.gz', 'r:gz') as tar:
- tar.extractall('extract_tar')
+
+ import os
+
+ 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(tar, "extract_tar")