Skip to content

gzip.compress incorrectly ignores level parameter #90425

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

Closed
rhpvorderman mannequin opened this issue Jan 5, 2022 · 2 comments
Closed

gzip.compress incorrectly ignores level parameter #90425

rhpvorderman mannequin opened this issue Jan 5, 2022 · 2 comments
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@rhpvorderman
Copy link
Mannequin

rhpvorderman mannequin commented Jan 5, 2022

BPO 46267
Nosy @rhpvorderman
PRs
  • bpo-46267: Correctly use compresslevel in gzip.compress  #30416
  • 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 = None
    created_at = <Date 2022-01-05.11:14:04.627>
    labels = ['type-bug', 'library', '3.11']
    title = 'gzip.compress incorrectly ignores level parameter'
    updated_at = <Date 2022-03-02.14:33:46.499>
    user = 'https://github.com/rhpvorderman'

    bugs.python.org fields:

    activity = <Date 2022-03-02.14:33:46.499>
    actor = 'rhpvorderman'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2022-01-05.11:14:04.627>
    creator = 'rhpvorderman'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46267
    keywords = ['patch']
    message_count = 2.0
    messages = ['409749', '414361']
    nosy_count = 1.0
    nosy_names = ['rhpvorderman']
    pr_nums = ['30416']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46267'
    versions = ['Python 3.11']

    @rhpvorderman
    Copy link
    Mannequin Author

    rhpvorderman mannequin commented Jan 5, 2022

    def compress(data, compresslevel=_COMPRESS_LEVEL_BEST, *, mtime=None):
        """Compress data in one shot and return the compressed string.
    compresslevel sets the compression level in range of 0-9.
    mtime can be used to set the modification time. The modification time is
    set to the current time by default.
    """
    if mtime == 0:
        # Use zlib as it creates the header with 0 mtime by default.
        # This is faster and with less overhead.
        return zlib.compress(data, level=compresslevel, wbits=31)
    header = _create_simple_gzip_header(compresslevel, mtime)
    trailer = struct.pack("<LL", zlib.crc32(data), (len(data) & 0xffffffff))
    # Wbits=-15 creates a raw deflate block.
    return header + zlib.compress(data, wbits=-15) + trailer
                                       ^ 
                                       Level should be here
    

    I noticed this while benchmarking against python-isal. This benchmarks add level 1 and it seemed oddly slow.

    This can be fixed easily. PR coming up.

    @rhpvorderman rhpvorderman mannequin added 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 5, 2022
    @rhpvorderman
    Copy link
    Mannequin Author

    rhpvorderman mannequin commented Mar 2, 2022

    ping

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 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

    0 participants