Skip to content

fix(app): bound memory and entry count when extracting zips - #8325

Closed
ha-am-dev wants to merge 1 commit into
modrinth:mainfrom
ha-am-dev:fix/app-zip-extraction-limits
Closed

ha-am-dev wants to merge 1 commit into
modrinth:mainfrom
ha-am-dev:fix/app-zip-extraction-limits

Conversation

@ha-am-dev

Copy link
Copy Markdown

fix(app): bound memory and entry count when extracting zips

What

file_extract_zip in apps/app/src/api/files.rs reads each archive entry into a
Vec<u8> with read_to_end and has no limits on entry size, total extracted size or
entry count, so a crafted archive can exhaust memory or disk when a user extracts it.

Change

Before extracting:

  • reject the archive if the sum of the declared entry sizes exceeds 2 GiB,
  • reject it if it contains more than 20 000 entries.

Per entry:

  • reject if the declared size exceeds 512 MiB,
  • read through take(limit + 1) and re-check the actual length, so an entry whose
    central directory size disagrees with its contents cannot exceed the budget.

Path handling is unchanged. validate_instance_file_write already resolves each
target and keeps writes inside the instance directory, so this is only about
resource use.

Notes for reviewers

  • The three constants are proposals (512 MiB per entry, 2 GiB total, 20 000 entries).
    They are generous for normal packs and easy to tune.
  • The archive itself is already read into memory before this function runs, so the
    compressed file size is bounded upstream; this bounds the expansion.

Testing

  • cargo clippy -p theseus -p theseus_gui --all-targets
  • Extract a normal archive (unchanged behaviour).
  • Extract an archive with one entry that declares a size above the limit; it should
    fail with the new error instead of allocating.
  • Extract an archive with more than 20 000 small entries; it should fail before
    writing anything.

@github-actions

Copy link
Copy Markdown
Contributor

Pull request changelog

App

Added

Changed

Deprecated

Removed

Fixed

Security

Website

Added

Changed

Deprecated

Removed

Fixed

Security

Hosting

Added

Changed

Deprecated

Removed

Fixed

Security

@mergify

mergify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

This pull request is closed, so it cannot be queued. Reopen it to get the box back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants