Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building with Python 3.11.4 generates tarfile.LinkOutsideDestinationError #674

Closed
effigies opened this issue Sep 5, 2023 · 8 comments · Fixed by #675
Closed

Building with Python 3.11.4 generates tarfile.LinkOutsideDestinationError #674

effigies opened this issue Sep 5, 2023 · 8 comments · Fixed by #675

Comments

@effigies
Copy link

effigies commented Sep 5, 2023

I have a project where the changelog lives in the root of the repository and I link to it from the doc directory so that it's part of our docs:

project/
  doc/
    source/
      changelog.rst -> ../../Changelog
      ...
    ...
  project/
    ...
  Changelog
  ...

As of Python 3.11.4, attempting to run python -m build produces:

❯ python -m build                                            
* Creating venv isolated environment...
* Installing packages in isolated environment... (hatch-vcs, hatchling)
* Getting build dependencies for sdist...
* Building sdist...

Traceback (most recent call last):
  File "/home/chris/mambaforge/envs/py3114/lib/python3.11/site-packages/build/__main__.py", line 388, in main
    built = build_call(
            ^^^^^^^^^^^
  File "/home/chris/mambaforge/envs/py3114/lib/python3.11/site-packages/build/__main__.py", line 247, in build_package_via_sdist
    t.extractall(sdist_out)
  File "/home/chris/mambaforge/envs/py3114/lib/python3.11/tarfile.py", line 2249, in extractall
    tarinfo = self._get_extract_tarinfo(member, filter_function, path)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chris/mambaforge/envs/py3114/lib/python3.11/tarfile.py", line 2303, in _get_extract_tarinfo
    self._handle_fatal_error(e)
  File "/home/chris/mambaforge/envs/py3114/lib/python3.11/tarfile.py", line 2301, in _get_extract_tarinfo
    tarinfo = filter_function(tarinfo, path)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chris/mambaforge/envs/py3114/lib/python3.11/tarfile.py", line 819, in data_filter
    new_attrs = _get_filtered_attrs(member, dest_path, True)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chris/mambaforge/envs/py3114/lib/python3.11/tarfile.py", line 806, in _get_filtered_attrs
    raise LinkOutsideDestinationError(member, target_path)
tarfile.LinkOutsideDestinationError: 'nibabel-5.2.0.dev36+g30ba615e/doc/source/changelog.rst' would link to '/Changelog', which is outside the destination

ERROR 'nibabel-5.2.0.dev36+g30ba615e/doc/source/changelog.rst' would link to '/Changelog', which is outside the destination

If I run either python -m build -s or python -m build -w, this error does not occur.

@henryiii
Copy link
Contributor

henryiii commented Sep 5, 2023

What version of CPython are using (including the patch value)? I think this is a bug that was fixed only in the latest patch release (fix in CPytjon landed something like two weeks ago). I think we are going to have to figure out how to work around the bug for the broken patch releases.

@effigies
Copy link
Author

effigies commented Sep 5, 2023

$ python
Python 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 18:08:17) [GCC 12.2.0] on linux

@henryiii
Copy link
Contributor

henryiii commented Sep 5, 2023

Oops, you mentioned it. Yep, 3.11.5 is the one with python/cpython#107845.

@effigies
Copy link
Author

effigies commented Sep 5, 2023

Got it. I assumed that, because this just started showing up in CI, that this was the latest Python. I can see if I can avoid 3.11.4.

@henryiii
Copy link
Contributor

henryiii commented Sep 5, 2023

It started showing up because we started using the data filter if it is present in build 1.0.0. I don’t remember exactly when it was added 3.11.3? Of course it’s a different patch number for every minor release of Python. 🤦

python -m build -s -w

will also work (it doesn’t unpack the SDist, the bug only gets hit if you unpack a tarball).

@effigies
Copy link
Author

effigies commented Sep 6, 2023

I think we are going to have to figure out how to work around the bug for the broken patch releases.

Just catching the error and saying that extraction is broken for packages with symlinks at the root for 3.11.4 but fixed in 3.11.5 would be good enough for me. I spent a bit trying to figure out if I did have broken links before I realized this was an upstream bug, so just clearly communicating the known failure condition would work.

@henryiii
Copy link
Contributor

henryiii commented Sep 6, 2023

You are in a rather special situation being able to control your Python patch version. Most users can't do that very easily. We can just avoid using the buggy data filter on versions of Python that contain the bug. (Also 3.8-3.10 still haven't had a release that fixes this bug).

@effigies
Copy link
Author

effigies commented Sep 6, 2023

Glad to see that the patch is not too painful.

effigies added a commit to nipy/nibabel that referenced this issue Sep 6, 2023
This reverts commit 3c94f8c.

This was not the correct way to specify a Python version, and I can't be
bothered to figure out the correct way, as this issue will be fixed in
build 1.0.1.

See bug report pypa/build#674
and fix pypa/build#675
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants