Skip to content

Bound ModelLoader::ReadString/ReadBytes against the mapped file size (OOB read on crafted .flm) - #702

Open
professor-moody wants to merge 1 commit into
ztxz16:masterfrom
professor-moody:fix-modelloader-readstring-oob
Open

professor-moody wants to merge 1 commit into
ztxz16:masterfrom
professor-moody:fix-modelloader-readstring-oob

Conversation

@professor-moody

Copy link
Copy Markdown

Loading a crafted .flm triggers an out-of-bounds read: ModelLoader::ReadString reads a length directly from the file and builds std::string(ptr, ptr + length) with no check against the mapped extent (ModelLoader is constructed with mapped_file->size but never consults it); ReadBytes is likewise unchecked. Reachable from WeightMap::LoadFromFile on file-controlled key/value entries.

This PR adds the missing bounds checks (reject length < 0 and ptr + length > data + size) using the size the loader already holds. See the accompanying issue #701 for the ASan-witnessed PoC and details.

Reported/fixed by Professor Moody (Halo Forge Labs), found with Crucible.

A crafted .flm whose string-length prefix (or ReadBytes length) exceeds the
mapped extent causes a read past the mmap during a normal model load, because
ReadString/ReadBytes never check the file-declared length against the size the
loader already holds. Reject length < 0 and ptr + length > data + size.

Fixes the OOB read reachable via WeightMap::LoadFromFile on an untrusted .flm.
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