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

Updating zip comment doesn't truncate the zip file #84286

Closed
yudilevi2 mannequin opened this issue Mar 29, 2020 · 5 comments
Closed

Updating zip comment doesn't truncate the zip file #84286

yudilevi2 mannequin opened this issue Mar 29, 2020 · 5 comments
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@yudilevi2
Copy link
Mannequin

yudilevi2 mannequin commented Mar 29, 2020

BPO 40105
Nosy @Yhg1s, @taleinat, @serhiy-storchaka, @miss-islington, @yudilevi2, @mzr
PRs
  • bpo-40105: fixed zip comment update #19333
  • bpo-40105: Truncating file if opened in append mode. #19337
  • [3.9] bpo-40105: ZipFile truncate in append mode with shorter comment (GH-19337) #22436
  • [3.8] bpo-40105: ZipFile truncate in append mode with shorter comment (GH-19337) #22437
  • [3.9] bpo-40105: ZipFile truncate in append mode with shorter comment (GH-19337) #22439
  • 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 2020-09-28.18:54:51.480>
    created_at = <Date 2020-03-29.20:48:23.704>
    labels = ['3.8', 'type-bug', 'library', '3.9', '3.10']
    title = "Updating zip comment doesn't truncate the zip file"
    updated_at = <Date 2020-09-28.20:18:50.333>
    user = 'https://github.com/yudilevi2'

    bugs.python.org fields:

    activity = <Date 2020-09-28.20:18:50.333>
    actor = 'miss-islington'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-09-28.18:54:51.480>
    closer = 'taleinat'
    components = ['Library (Lib)']
    creation = <Date 2020-03-29.20:48:23.704>
    creator = 'yudilevi'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40105
    keywords = ['patch']
    message_count = 5.0
    messages = ['365278', '377614', '377615', '377617', '377623']
    nosy_count = 6.0
    nosy_names = ['twouters', 'taleinat', 'serhiy.storchaka', 'miss-islington', 'yudilevi', 'mzr']
    pr_nums = ['19333', '19337', '22436', '22437', '22439']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue40105'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @yudilevi2
    Copy link
    Mannequin Author

    yudilevi2 mannequin commented Mar 29, 2020

    Updating the zip file comment to a shorter comment should truncate the zip file at the end of the new comment.
    Instead, the new comment is written to the zip file but the file length stays the same.

    For example, for a zip file that has the following zip comment:
    b'This is my old amazing comment, I bet you really like it!' # 57 character long

    Executing the following code:

    zipFile = ZipFile(filePath, 'a')
    zipFile.comment = b'My new shorter comment' # 22 character long
    zipFile.close()

    Will actually update the comment length in the zip header to the correct new length (22), but the bytecode will still have the following data:
    b'My new shorter comment comment, I bet you really like it!'

    Python reads the comment correctly since it relies on the comment length from the metadata (as far as I can tell), but the file is corrupt.

    This is similar to the following old issue -
    https://bugs.python.org/issue9239

    But I wasn't sure whether to try and re-open that old one or create a new one.

    Tested on version 3.8.2 (Windows 10).

    Thanks!

    @yudilevi2 yudilevi2 mannequin added 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 29, 2020
    @taleinat
    Copy link
    Contributor

    New changeset ff9147d by Jan Mazur in branch 'master':
    bpo-40105: ZipFile truncate in append mode with shorter comment (GH-19337)
    ff9147d

    @taleinat
    Copy link
    Contributor

    Thanks for the report and initial PR, Yudi!

    Thanks for the second PR, Jan!

    @taleinat taleinat added 3.9 only security fixes 3.10 only security fixes labels Sep 28, 2020
    @miss-islington
    Copy link
    Contributor

    New changeset e400840 by Miss Islington (bot) in branch '3.8':
    bpo-40105: ZipFile truncate in append mode with shorter comment (GH-19337)
    e400840

    @miss-islington
    Copy link
    Contributor

    New changeset 048f54d by Miss Islington (bot) in branch '3.9':
    bpo-40105: ZipFile truncate in append mode with shorter comment (GH-19337)
    048f54d

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants