This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: zipapps execute symlinks as if they are code
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.9, Python 3.8, Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Anthony Sottile, FFY00
Priority: normal Keywords: patch

Created on 2020-05-05 22:55 by Anthony Sottile, last changed 2022-04-11 14:59 by admin.

File name Uploaded Description Edit
zipimporter-symlink.patch FFY00, 2020-05-08 02:21
Messages (2)
msg368212 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2020-05-05 22:55
$ ln -s 'import os; os.system("echo hi")'
$ ls -al
total 8
drwxr-xr-x 2 asottile asottile 4096 May  5 15:55 .
drwxr-xr-x 3 asottile asottile 4096 May  5 14:50 ..
lrwxrwxrwx 1 asottile asottile   31 May  5 15:55 -> 'import os; os.system("echo hi")'
$ zip --symlinks 
  adding: (stored 0%)
$ python3

I expect the output to be similar to running ``:

$ python3 
python3: can't open file '': [Errno 2] No such file or directory

(real usecase, I wanted `` to be a symlink but got a very strange NameError and traced it down to executing the symlink target  name instead of the symlink destination)
msg368403 - (view) Author: Filipe Laíns (FFY00) * (Python triager) Date: 2020-05-08 02:21
I tracked this down to zipimporter. I have one untested patch, when I run python from my development tree for some reason the zipimport definition at Lib/ is not used. I assume something weird is going on because of the frozen circular imports. I would appreaciate it if someone could explain how this works and how I get the correct zipimporter definition to be used.
Date User Action Args
2022-04-11 14:59:30adminsetgithub: 84705
2020-05-08 02:21:52FFY00setfiles: + zipimporter-symlink.patch

nosy: + FFY00
messages: + msg368403

keywords: + patch
2020-05-05 22:55:41Anthony Sottilecreate