FFFF Stack buffer overflow reading encrypted entry with small compressed_size · Issue #1094 · zlib-ng/minizip-ng · GitHub
[go: up one dir, main page]

Skip to content

Stack buffer overflow reading encrypted entry with small compressed_size #1094

Backlog

Description

@merrowd

Version: minizip-ng 4.2.2

Found a stack buffer overflow in 4.2.2. When an encrypted entry's central directory compressed_size is smaller than the encryption header + footer, the decrypt streams compute a negative bytes_to_read and pass it down. mz_stream_os_read casts it to size_t for fread, which drains ~4 KB into the caller's buffer. For STORE + encrypted entries the destination is the caller's buffer, so anything under ~4 KB overflows with bytes from the archive.

Repro: AES-256 STORE entry, CD compressed_size patched 5528 -> 12, opened with the right password through the low-level mz_zip API over a file-backed stream. ASan: stack-buffer-overflow, WRITE of size 4027 past a 1024-byte stack buffer. Trace: fread <- mz_stream_os_read (mz_strm_os_posix.c:121) <- mz_stream_wzaes_read (mz_strm_wzaes.c:188) <- mz_stream_raw_read <- mz_zip_entry_read.

Same thing with PKWARE, compressed_size 5512 -> 5, writes 4044 bytes.

Scope: only the low-level mz_zip API with a file-backed stream. mz_zip_reader_open_file and the in-memory paths return 0 on the negative size, and the CLI fails cleanly. DEFLATE entries land in zlib's internal buffer so no overflow on glibc there, but the accounting is still wrong.

Fix idea: clamp bytes_to_read at 0 in mz_stream_wzaes_read and mz_stream_pkcrypt_read, and/or reject the entry in mz_zip_entry_open_int when compressed_size < header + footer for encrypted entries.

PoC archives and the reproducer harness are attached.

min_aes_patched.zip
min_pk_patched.zip
harness_os.c

Activity

  1. coderabbitai commented on Dec 1, 2026

    @coderabbitai
    🔗 Related PRs

    #1072 - zip: verify WinZip AES authentication on read close [open]


    📝 Issue Planner

    Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

    • Create Plan

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  2. merrowd commented on Dec 1, 2026

    @merrowd
    Author

    The password for both PoC archives is test123. It is also hardcoded in the attached harness_os.c (line 38).

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0