Skip to content

Validate ZIP and save-state bounds before reading - #400

Open
acts-1631 wants to merge 2 commits into
bsnes-emu:masterfrom
acts-1631:fix/archive-state-bounds
Open

acts-1631 wants to merge 2 commits into
bsnes-emu:masterfrom
acts-1631:fix/archive-state-bounds

Conversation

@acts-1631

Copy link
Copy Markdown

Decode::ZIP::open follows central-directory and local-file offsets without
checking that they stay inside the mapped archive. A malformed game or state
ZIP can crash bsnes while it parses or extracts an entry. Validate the
directory, local header, and payload ranges before using them.

Program::loadStateData accepts a short .bst file that can reach
System::unserialize without a complete header. StateManager::updateSelection
can also copy a truncated preview as a full image. Validate the state
sections and preview size, then require the serializer capacity to match
the declared system state size before deserializing.

A ZIP can point its central directory, local headers, or compressed
data outside the mapped file. Validate each range before reading it
so a malformed game or state archive cannot crash the decoder.
A short state can reach System::unserialize with too little data for
its header. Malformed previews can also be copied as full images.
Check file section lengths, decoded preview size, and serializer
capacity before consuming state data.
@Screwtapello

Copy link
Copy Markdown
Contributor

Thanks for looking into this. I'm curious - did you run into this problem yourself and try to solve it, or were you just in the mood to look for missing bounds-checks?

@acts-1631

Copy link
Copy Markdown
Author

Thanks for looking into this. I'm curious - did you run into this problem yourself and try to solve it, or were you just in the mood to look for missing bounds-checks?

Sometimes you just get in that mood man.

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.

2 participants