Skip to content

Handle invalid and oversized MIX file indexes#325

Open
NayiemW wants to merge 1 commit into
CnCNet:masterfrom
the-real-antares:fix-mix-index-hardening
Open

Handle invalid and oversized MIX file indexes#325
NayiemW wants to merge 1 commit into
CnCNet:masterfrom
the-real-antares:fix-mix-index-hardening

Conversation

@NayiemW

@NayiemW NayiemW commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Follow-up to [36209485](36209485), completing the remaining MIX index hardening.

MIX headers store the number of archive entries as an unsigned 16-bit value. WAE previously read this field using BitConverter.ToInt16, which interpreted counts above 32,767 as negative numbers.

As a result, sufficiently large MIX archives could not be indexed correctly and would silently appear empty. This change reads the field as a ushort, allowing the full range of valid MIX entry counts.

The parser now also rejects indexes with a file count of zero. A zero count generally indicates that the index is invalid—for example, because the archive is truncated or an encrypted index could not be decrypted correctly. Previously, such archives were silently registered as empty, hiding the underlying parsing failure.

Invalid MIX archives now produce a clear parsing exception. During archive discovery, that exception is logged and the affected archive is skipped, allowing the editor to continue loading instead of crashing because of a single corrupt MIX file.

Together, these changes ensure that WAE:

  • correctly handles MIX archives containing more than 32,767 entries;
  • rejects malformed or incorrectly decrypted indexes instead of treating them as valid empty archives; and
  • continues loading when an individual MIX archive cannot be parsed.

The MIX header's file count was read as a signed 16-bit value, so archives with more than 32767 entries produced a negative count and silently registered as empty. Read it as unsigned. A zero file count means the index - or its decryption - came out garbage; throw instead of silently registering an empty MIX, and log and skip such archives when loading so a single corrupt MIX file does not crash the editor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant