# Buggy code
def _normpath(path):
    path = os.path.normpath(path)
    if path.startswith(".") or os.path.isabs(path):
        raise UnsafeArchiveError("Archive at %s is not safe." % path)
    if path.endswith("~") or os.path.basename(path).startswith("."):
        return None
    return path


# Traceback (UnsafeArchiveError)











Dl Completed...: 0 url [00:00, ? url/s]
Dl Size...: 0 MiB [00:00, ? MiB/s]

Dl Completed...:   0%|          | 0/1 [00:00<?, ? url/s]
Dl Size...: 0 MiB [00:00, ? MiB/s]

Dl Completed...:   0%|          | 0/1 [00:00<?, ? url/s]
Dl Size...: 0 MiB [00:00, ? MiB/s]

Dl Completed...: 100%|██████████| 1/1 [00:01<00:00,  1.50s/ url]
Dl Size...: 0 MiB [00:01, ? MiB/s]

Dl Completed...: 100%|██████████| 1/1 [00:01<00:00,  1.50s/ url]
Dl Size...: 0 MiB [00:01, ? MiB/s]

Extraction completed...:   0%|          | 0/1 [00:01<?, ? file/s]



---------------------------------------------------------------------------
UnsafeArchiveError                        Traceback (most recent call last)
~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_datasets/core/download/extractor.py in _sync_extract(self, resource, to_path)
     89     try:
---> 90       for path, handle in iter_archive(from_path, method):
     91         _copy(handle, path and os.path.join(to_path_tmp, path) or to_path_tmp)

~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_datasets/core/download/extractor.py in iter_tar(arch_f, gz)
    139       if extract_file:  # File with data (not directory):
--> 140         path = _normpath(member.path)
    141         if not path:

~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_datasets/core/download/extractor.py in _normpath(path)
    116   if path.startswith('.') or os.path.isabs(path):
--> 117     raise UnsafeArchiveError('Archive at %s is not safe.' % path)
    118   if path.endswith('~') or os.path.basename(path).startswith('.'):

UnsafeArchiveError: Archive at ._lists is not safe.

During handling of the above exception, another exception occurred:

ExtractError                              Traceback (most recent call last)
<ipython-input-1-5ecf00c50c12> in <module>
      5 _SPLIT_URL = "http://www.vision.caltech.edu/visipedia-data/CUB-200/lists.tgz"
      6 dl = tfds.download.DownloadManager(download_dir=download_dir)
----> 7 train_test_split_archive = dl.download_and_extract([_SPLIT_URL])

~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_datasets/core/download/download_manager.py in download_and_extract(self, url_or_urls)
    329     with self._downloader.tqdm():
    330       with self._extractor.tqdm():
--> 331         return _map_promise(self._download_extract, url_or_urls)
    332 
    333   @property

~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_datasets/core/download/download_manager.py in _map_promise(map_fn, all_inputs)
    365   """Map the function into each element and resolve the promise."""
    366   all_promises = utils.map_nested(map_fn, all_inputs)  # Apply the function
--> 367   res = utils.map_nested(_wait_on_promise, all_promises)
    368   return res

~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_datasets/core/utils/py_utils.py in map_nested(function, data_struct, dict_only, map_tuple)
    136     if isinstance(data_struct, tuple(types)):
    137       mapped = [map_nested(function, v, dict_only, map_tuple)
--> 138                 for v in data_struct]
    139       if isinstance(data_struct, list):
    140         return mapped

~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_datasets/core/utils/py_utils.py in <listcomp>(.0)
    136     if isinstance(data_struct, tuple(types)):
    137       mapped = [map_nested(function, v, dict_only, map_tuple)
--> 138                 for v in data_struct]
    139       if isinstance(data_struct, list):
    140         return mapped

~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_datasets/core/utils/py_utils.py in map_nested(function, data_struct, dict_only, map_tuple)
    142         return tuple(mapped)
    143   # Singleton
--> 144   return function(data_struct)
    145 
    146 

~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_datasets/core/download/download_manager.py in _wait_on_promise(p)
    349 
    350   def _wait_on_promise(p):
--> 351     return p.get()
    352 
    353 else:

~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/promise/promise.py in get(self, timeout)
    508         target = self._target()
    509         self._wait(timeout or DEFAULT_TIMEOUT)
--> 510         return self._target_settled_value(_raise=True)
    511 
    512     def _target_settled_value(self, _raise=False):

~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/promise/promise.py in _target_settled_value(self, _raise)
    512     def _target_settled_value(self, _raise=False):
    513         # type: (bool) -> Any
--> 514         return self._target()._settled_value(_raise)
    515 
    516     _value = _reason = _target_settled_value

~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/promise/promise.py in _settled_value(self, _raise)
    222             if _raise:
    223                 raise_val = self._fulfillment_handler0
--> 224                 reraise(type(raise_val), raise_val, self._traceback)
    225             return self._fulfillment_handler0
    226 

~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/six.py in reraise(tp, value, tb)
    691             if value.__traceback__ is not tb:
    692                 raise value.with_traceback(tb)
--> 693             raise value
    694         finally:
    695             value = None

~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/promise/promise.py in handle_future_result(future)
    840         # type: (Any) -> None
    841         try:
--> 842             resolve(future.result())
    843         except Exception as e:
    844             tb = exc_info()[2]

~/anaconda3/envs/tensorflow/lib/python3.6/concurrent/futures/_base.py in result(self, timeout)
    423                 raise CancelledError()
    424             elif self._state == FINISHED:
--> 425                 return self.__get_result()
    426 
    427             self._condition.wait(timeout)

~/anaconda3/envs/tensorflow/lib/python3.6/concurrent/futures/_base.py in __get_result(self)
    382     def __get_result(self):
    383         if self._exception:
--> 384             raise self._exception
    385         else:
    386             return self._result

~/anaconda3/envs/tensorflow/lib/python3.6/concurrent/futures/thread.py in run(self)
     54 
     55         try:
---> 56             result = self.fn(*self.args, **self.kwargs)
     57         except BaseException as exc:
     58             self.future.set_exception(exc)

~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow_datasets/core/download/extractor.py in _sync_extract(self, resource, to_path)
     91         _copy(handle, path and os.path.join(to_path_tmp, path) or to_path_tmp)
     92     except BaseException as err:
---> 93       raise ExtractError(resource, err)
     94     # `tf.io.gfile.Rename(overwrite=True)` doesn't work for non empty
     95     # directories, so delete destination first, if it already exists.

ExtractError: Error while extracting file /home/iswariya/Downloads/working/visio.calte.edu_visip-data_CUB-200_listskJqxLvtbYiwxBKy5Tl3x83yeAHQg_hP2VQx6CYqcVLk.tgz (http://www.vision.caltech.edu/visipedia-data/CUB-200/lists.tgz): Archive at ._lists is not safe..

# Fixed code
def _normpath(path):
    path = os.path.normpath(path)
    if (
        path.startswith(".")
        or os.path.isabs(path)
        or path.endswith("~")
        or os.path.basename(path).startswith(".")
    ):
        return None
    return path