Skip to content

mrpack4server silently ignores local.mrpack when Java cannot open it as ZIP #9

Description

@LingYiWu015

Issue: mrpack4server silently falls back to setup when local.mrpack cannot be opened by Java ZIP

Environment

  • Windows 11 / Windows Server
  • Java 17 (Azul Zulu 17)
  • mrpack4server 0.5.0, mrpack4server-0.5.0-jvm17.jar
  • Modrinth .mrpack file exported from a Chinese modpack, about 172 MB

Steps To Reproduce

  1. Create a server directory.
  2. Put mrpack4server-0.5.0-jvm17.jar in the directory and rename it to server.jar.
  3. Put the .mrpack file in the same directory and rename it to local.mrpack.
  4. Run:
java -jar server.jar nogui

Expected:

Starting installation of <modpack> (<version>)

Actual:

Couldn't find modpack definition! Creating a new one...
Provide modpack name, it's id or url linking to it.
Prefix with ? to search.
>

Root Cause

java.util.zip cannot open the .mrpack file:

java.util.zip.ZipException: invalid CEN header (bad entry name)

PowerShell/.NET can open the same file and read modrinth.index.json correctly, which suggests the ZIP central directory contains entry names that Java does not accept, likely because the exporter wrote non-UTF-8 or otherwise incompatible entry names.

In resolveModpackInfoExternal, the FileSystems.newFileSystem(possibleMrpack) failure is swallowed:

try (var zip = FileSystems.newFileSystem(possibleMrpack)) {
    ...
} catch (Throwable e) {
    // ignored
}

As a result, mrpack4server treats the existing local.mrpack as missing and opens the interactive setup prompt.

Workaround

Rezip the same entries with a standard UTF-8 ZIP writer. For example, PowerShell can rewrite the archive without changing the file contents:

Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.IO.Compression.FileSystem

$src = "C:\path\to\local-original.mrpack"
$out = "C:\path\to\local-fixed.mrpack"

$sourceZip = [System.IO.Compression.ZipFile]::OpenRead($src)
$targetZip = [System.IO.Compression.ZipFile]::Open($out, [System.IO.Compression.ZipArchiveMode]::Create)

foreach ($entry in $sourceZip.Entries) {
    $name = $entry.FullName.Replace('\', '/')
    $newEntry = $targetZip.CreateEntry($name, [System.IO.Compression.CompressionLevel]::Optimal)
    if (-not $entry.FullName.EndsWith('/')) {
        $input = $entry.Open()
        $output = $newEntry.Open()
        try { $input.CopyTo($output) } finally { $output.Dispose(); $input.Dispose() }
    } else {
        $newEntry.Open().Dispose()
    }
}

$targetZip.Dispose()
$sourceZip.Dispose()

After replacing local.mrpack with the fixed archive, mrpack4server detects it and installs the modpack normally.

Suggested Fix

  1. Do not swallow the underlying ZIP exception when local.mrpack exists but cannot be opened.
  2. Log the exception and print a clear message such as:
Found local.mrpack but Java could not open it as a ZIP archive. Run `jar tf local.mrpack` for more details.
  1. Optionally attempt a repair path that re-writes the archive using a standard ZIP writer when Java's built-in ZIP reader rejects the entry names.
  2. Modrinth App and pack export tools should ensure .mrpack ZIP entry names are valid UTF-8.

Repro Artifact

The original file is kept as local-original.mrpack; the fixed archive is local.mrpack in the user's server directory.
problem mrpack file:
https://cdn.bbsmc.net/bbsmc/data/YtS91hhr/versions/TR5ISmKg/FarmingTales_Forge%E2%85%A1%20v1.5.1.mrpack

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions