Skip to content

shutil.make_archive() adds the zip archive to itself when it is inside the archived tree #161112

Closed

Description

@gpshead

Bug report

Bug description:

With the "zip" format, shutil.make_archive() adds the archive it is writing to itself when the output path is inside the directory being archived. _make_zipfile() walks the tree and writes every regular file it finds, including the partly written archive (TarFile.add() already skips the archive for the tar formats).

import os, shutil, zipfile
os.mkdir('d'); os.chdir('d')
open('f', 'w').close()
shutil.make_archive('test', 'zip')
print(zipfile.ZipFile('test.zip').namelist())  # ['test.zip', 'f']

The archive member is a truncated copy of the output. If a symlink in the tree points at the archive and is reached after some data has been flushed, the archive keeps growing until the disk is full or a file size limit is hit (OSError: [Errno 27] File too large).

gh-104527 fixed the same problem in zipapp.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. self-assigned this
    on Nov 1, 2026
  2. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 1, 2026
  3. added a commit that references this issue on Nov 1, 2026
  4. added 2 commits that reference this issue on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions