Skip to content

zlib: createUnzip().reset() does not restore auto-detection state #64619

Closed

Description

@Archkon

Version

latest main branch

Platform

7.1.3-arch1-3

Subsystem

zlib

What steps will reproduce the bug?

'use strict';

const zlib = require('node:zlib');

const output = [];
const unzip = zlib.createUnzip();

unzip.on('data', (chunk) => output.push(chunk));
unzip.on('error', console.error);
unzip.on('end', () => {
  console.log(Buffer.concat(output).toString());
});

unzip.write(Buffer.from([0x1f]), () => {
  unzip.reset();
  unzip.end(zlib.gzipSync('hello'));
});

How often does it reproduce? Is there a required condition?

Every

What is the expected behavior? Why is that the expected behavior?

The reset stream should behave like a newly created Unzip stream and output:

hello

This is consistent with the documented behavior that zlib.reset() resets the compressor/decompressor to factory defaults.

What do you see instead?

The stream emits Z_DATA_ERROR.

After reading 0x1f, gzip_id_bytes_read_ is set to 1, while mode_ remains UNZIP. The reset implementation does not handle UNZIP, so the underlying inflater and the gzip magic-byte counter are not reset.

The same state leak also occurs after auto-detection completes: mode_ remains INFLATE or GUNZIP instead of returning to UNZIP, so the next stream does not start with fresh format detection.

Additional information

No response

Activity

  1. github-actions commented on Oct 19, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 90 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  2. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Oct 19, 2026
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

    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions