Skip to content

buffer overflow in Zipfile when wrinting more than 2gig file #50683

Closed

Description

@segfault42
mannequin
BPO 6434
Nosy @amauryfa
Superseder
  • bpo-9720: zipfile writes incorrect local file header for large files in zip64
  • Files
  • zipfile.py: zipfile.py lib
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2011-11-03.12:17:17.767>
    created_at = <Date 2009-07-07.17:10:57.536>
    labels = ['type-bug', 'library']
    title = 'buffer overflow in Zipfile when wrinting more than 2gig file'
    updated_at = <Date 2011-11-03.12:17:17.766>
    user = 'https://bugs.python.org/segfault42'

    bugs.python.org fields:

    activity = <Date 2011-11-03.12:17:17.766>
    actor = 'nadeem.vawda'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-11-03.12:17:17.767>
    closer = 'nadeem.vawda'
    components = ['Library (Lib)']
    creation = <Date 2009-07-07.17:10:57.536>
    creator = 'segfault42'
    dependencies = []
    files = ['14469']
    hgrepos = []
    issue_num = 6434
    keywords = []
    message_count = 11.0
    messages = ['90242', '90243', '90261', '90282', '92142', '92147', '121826', '146505', '146527', '146911', '146922']
    nosy_count = 6.0
    nosy_names = ['amaury.forgeotdarc', 'nadeem.vawda', 'lambacck', 'segfault42', 'enlavin', 'Paul']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '9720'
    type = 'behavior'
    url = 'https://bugs.python.org/issue6434'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

    Activity

    1. segfault42 commented on Jul 7, 2009

      segfault42mannequin
      MannequinAuthor

      Hello,

      I have a problem with the librairy zipfile.py
      http://svn.python.org/view/python/trunk/Lib/zipfile.py?revision=73565&view=markup

      Zinfo structure limit the size of a file to an int max value with the
      ZIP64_LIMIT value ( equal to "(1 << 31) - 1 " so to 2147483647 .

      The problem is happening when you write a big file in the line 1095 :

      self.fp.write(struct.pack("<lLL", zinfo.CRC, zinfo.compress_size,
                       zinfo.file_size))

      zinfo.file_size is limited to a int size and if you have a file bigger
      than ZIP64_LIMIT you make a buffer overflow even if you set the flag
      allowZip64 to true.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Jul 7, 2009
    3. segfault42 commented on Jul 7, 2009

      segfault42mannequin
      MannequinAuthor

      look like bpo-1182788

    4. added
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Jul 7, 2009
    5. amauryfa commented on Jul 8, 2009

      @amauryfa
      Contributor

      I don't see how it can be a buffer overflow. Or is it an exception
      raised by the struct.pack function?

    6. segfault42 commented on Jul 8, 2009

      segfault42mannequin
      MannequinAuthor

      yes it's zinfo.file_size which is bigger than the long specify in the
      struct.pack

      There's must have a solution with the extra header because a lot of tools
      can zip big file and these zip file can be open by zipfile.py

      it's easy to reproduice with a big file of 3 gig.

      i think that the problem come from that the write methode do not take
      care of the flag allowZip64

    7. segfault42 commented on Sep 1, 2009

      segfault42mannequin
      MannequinAuthor

      still no one to help on this problem ? is someone has some idea ?

    8. amauryfa commented on Sep 1, 2009

      @amauryfa
      Contributor

      I did reproduce the problem, but I'm sorry I don't have the time to fix
      it. However, I will review any proposed patch.

    9. lambacck commented on Nov 21, 2010

      lambacckmannequin
      Mannequin

      This should be closed as a dup of bpo-1182788 which the OP identified as being the same bug and which is now fixed due to the implementation. of ZIP64.

    10. Paul commented on Oct 27, 2011

      Paulmannequin
      Mannequin

      This is a problem with python2.7 as well. A change in struct between python2.6 and 2.7 raises an exception on overflow instead of silently allowing it. This prevents zipping any file larger than 4.5G. This exception concurs when writing the 32-bit headers (which are not used on large files anyway)

      The patch should be simple. Just wrap line 1100:
      ...struct.pack("<LLL",...
      with a try: except: to revert to the old behavior. Alternatively, check if size is bigger than ZIP64_LIMIT and set to anything less than ZIP64_LIMIT.

    11. Paul commented on Oct 27, 2011

      Paulmannequin
      Mannequin

      I attempted to "re-allow overflow" in the struct(...) call by replacing zinfo.file_size with ZIP64_LIMIT % zinfo.file_size in zipfile.py, and successfully produced a compressed file from a 10G file, but the resulting compressed file could not be uncompressed and was deemed "invalid" by any unzip util I tried.

    12. enlavin commented on Nov 3, 2011

      enlavinmannequin
      Mannequin

      I think it's a dup of http://bugs.python.org/issue9720

      That issue has a patch that allows the generation of zip files with >2GB files.

    13. nadeemvawda commented on Nov 3, 2011

      nadeemvawdamannequin
      Mannequin

      Marking as duplicate.

    14. added
      type-bugAn unexpected behavior, bug, or error
      and removed
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Nov 3, 2011
    15. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      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