Skip to content

fix(io): harden the binary FBX parser against hostile files - #1

Merged
mattscott merged 1 commit into
mainfrom
fix/fbx-parser-hardening
Nov 21, 2026
Merged

mattscott merged 1 commit into
mainfrom
fix/fbx-parser-hardening

Conversation

@mattscott

Copy link
Copy Markdown
Owner

What and why

The binary FBX parser trusted the lengths and offsets inside the file. A crafted .fbx could hang the parser, exhaust memory, or overflow the stack, and a stack overflow kills the host process outright in .NET. These are denial-of-service bugs for anyone who embeds the library and opens untrusted files.

Attack Before After
100,000 nested records stack overflow (process dies) InvalidDataException, depth capped at 64
End offset pointing backwards wrong exception / possible loop rejected; offsets must move forward
Array claiming 10M doubles from 4 compressed bytes allocates 80 MB first rejected before inflating (DEFLATE ratio bound)
Array length int.MaxValue wrong exception rejected (512 MB cap)
Negative string length / record past EOF ArgumentOutOfRangeException InvalidDataException

How it was tested

  • New FbxHostileInputTests build each hostile file by hand. Against the old parser, the 5 runnable cases fail; the nesting case is not run against the old code because it would kill the test host.
  • The full suite passes locally, and the existing FBX round-trip tests are unchanged.
  • The same parser change ships in quadremesh, normalbake and uvbake.

Checklist

  • dotnet test passes locally
  • Tests cover the change
  • Output stays deterministic
  • No code copied from other projects

🤖 Generated with Claude Code

https://claude.ai/code/session_01S5ts9QgA8bk8NBJJuMyTKr

Every length and offset read from an FBX file is now validated before use.
Previously a crafted file could:
- overflow the stack via unbounded record nesting (uncatchable; kills the process)
- send the parser backwards with an end offset before the record start
- force huge allocations from a declared array length (incl. zlib bombs)
- crash with ArgumentOutOfRange/IndexOutOfRange instead of a clean error

Now: nesting is capped at 64, record offsets must move forward and stay
in the file, arrays are capped at 512 MB and must be reachable at
DEFLATE's max ratio, inflated size is verified, and any malformed input
throws InvalidDataException. Adds hostile-input tests for each case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S5ts9QgA8bk8NBJJuMyTKr
@mattscott
mattscott merged commit 94c79c6 into main Nov 21, 2026
2 checks passed
@mattscott
mattscott deleted the fix/fbx-parser-hardening branch November 21, 2026 23:45
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