Skip to content

Work around NLTK v3.9.3 regression#2042

Merged
edmorley merged 1 commit intomainfrom
nltk-workaround
Mar 2, 2026
Merged

Work around NLTK v3.9.3 regression#2042
edmorley merged 1 commit intomainfrom
nltk-workaround

Conversation

@edmorley
Copy link
Member

@edmorley edmorley commented Mar 2, 2026

In NLTK v3.9.3, a new security check was added for the Zip Slip issue:
nltk/nltk#3468

This change unfortunately contained a bug that causes false positive security errors when packages are downloaded to a symlinked path, since the new check doesn't use abspath vs realpath consistently:
nltk/nltk#3509

This causes errors like:

-----> Downloading NLTK packages: punkt punkt_tab
       <frozen runpy>:128: RuntimeWarning: 'nltk.downloader' found in sys.modules after import of package 'nltk', but prior to execution of 'nltk.downloader'; this may result in unpredictable behaviour
       [nltk_data] Downloading package punkt to
       [nltk_data]     /app/.heroku/python/nltk_data...
       [nltk_data]   Unzipping tokenizers/punkt.zip.
       [nltk_data] Zip Slip blocked: punkt/
       Error installing package. Retry? [n/y/e]
       Traceback (most recent call last):
         File "<frozen runpy>", line 198, in _run_module_as_main
         File "<frozen runpy>", line 88, in _run_code
         File "/app/.heroku/python/lib/python3.12/site-packages/nltk/downloader.py", line 2631, in <module>
           rv = downloader.download(
                ^^^^^^^^^^^^^^^^^^^^
         File "/app/.heroku/python/lib/python3.12/site-packages/nltk/downloader.py", line 773, in download
           choice = input().strip()
                    ^^^^^^^
       EOFError: EOF when reading a line

See also:
https://github.com/heroku/heroku-buildpack-python/actions/runs/22545824206/job/65308000022#step:5:539

Until upstream fix this regression, we can work around it by always passing the raw path for Python home instead of the symlinked path. (We generally prefer using the symlinked path where possible, to ensure the paths used/displayed match between build time and run time, given the build directory is different from the run directory.)

Longer term I will be deprecating and that removing support for nltk.txt since it's a Heroku-proprietary invention that's unnecessary given most users instead either commit the NLTK corpora or use the post_compile hook feature instead.

Fixes #2037.
GUS-W-21410908.

In NLTK v3.9.3, a new security check was added for the Zip Slip issue:
nltk/nltk#3468

This change unfortunately contained a bug that causes false positive
security errors when packages are downloaded to a symlinked path,
since the new check doesn't use `abspath` vs `realpath` consistently:
nltk/nltk#3509

This causes errors like:

```
-----> Downloading NLTK packages: punkt punkt_tab
       <frozen runpy>:128: RuntimeWarning: 'nltk.downloader' found in sys.modules after import of package 'nltk', but prior to execution of 'nltk.downloader'; this may result in unpredictable behaviour
       [nltk_data] Downloading package punkt to
       [nltk_data]     /app/.heroku/python/nltk_data...
       [nltk_data]   Unzipping tokenizers/punkt.zip.
       [nltk_data] Zip Slip blocked: punkt/
       Error installing package. Retry? [n/y/e]
       Traceback (most recent call last):
         File "<frozen runpy>", line 198, in _run_module_as_main
         File "<frozen runpy>", line 88, in _run_code
         File "/app/.heroku/python/lib/python3.12/site-packages/nltk/downloader.py", line 2631, in <module>
           rv = downloader.download(
                ^^^^^^^^^^^^^^^^^^^^
         File "/app/.heroku/python/lib/python3.12/site-packages/nltk/downloader.py", line 773, in download
           choice = input().strip()
                    ^^^^^^^
       EOFError: EOF when reading a line
```

See also:
https://github.com/heroku/heroku-buildpack-python/actions/runs/22545824206/job/65308000022#step:5:539

Until upstream fix this regression, we can work around it by always
passing the raw path to Python home instead of the symlinked path.
(We generally prefer using the symlinked path where possible, to
ensure the paths used/displayed match between build time and
run time, given the build directory is difference from the run directory.)

Longer term I will be deprecating and that removing support for `nltk.txt`
since it's a Heroku-proprietary invention that's unnecessary given most
users instead either commit the NLTK corpora or use the post_compile
hook feature instead.

Fixes #2037.
GUS-W-21410908.
@edmorley edmorley self-assigned this Mar 2, 2026
@edmorley edmorley marked this pull request as ready for review March 2, 2026 16:29
@edmorley edmorley requested a review from a team as a code owner March 2, 2026 16:29
@edmorley edmorley enabled auto-merge (squash) March 2, 2026 16:42
@edmorley edmorley merged commit 361215e into main Mar 2, 2026
5 of 6 checks passed
@edmorley edmorley deleted the nltk-workaround branch March 2, 2026 17:14
@heroku-linguist heroku-linguist bot mentioned this pull request Mar 2, 2026
@edmorley
Copy link
Member Author

edmorley commented Mar 2, 2026

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 this pull request may close these issues.

ZipSlip fix in NLTK breaks builds

2 participants