Repository navigation
B3D: validate chunk size against buffer and parent chunk - #6705
Conversation
ReadChunk() pushed _pos + sz onto the chunk stack using an unvalidated, attacker-controlled size. As a result ChunkSize() (computed as _stack.back() - _pos) could either report a value far larger than the remaining file, or underflow to a huge size_t when a nested chunk overran its parent. The element counts derived from ChunkSize() in ReadVRTS() and ReadTRIS() then drove unbounded _vertices.resize() / new aiFace[] allocations on crafted .b3d input. Validate each chunk's extent at the ReadChunk() chokepoint (it must fit within the file and within its enclosing chunk) and make ChunkSize() underflow-safe, hardening every downstream chunk consumer at once.
|
Strix is installed on this repository, but we could not run this PR security review because this workspace does not have an active plan. If you'd like to continue receiving code reviews, you can add a payment method or manage billing here. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesB3D Chunk Parsing Hardening
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Merged, thank you for your contribution. |
|
ReadChunk() pushed _pos + sz onto the chunk stack using an unvalidated, attacker-controlled size. As a result ChunkSize() (computed as _stack.back() - _pos) could either report a value far larger than the remaining file, or underflow to a huge size_t when a nested chunk overran its parent. The element counts derived from ChunkSize() in ReadVRTS() and ReadTRIS() then drove unbounded _vertices.resize() / new aiFace[] allocations on crafted .b3d input. Validate each chunk's extent at the ReadChunk() chokepoint (it must fit within the file and within its enclosing chunk) and make ChunkSize() underflow-safe, hardening every downstream chunk consumer at once. Co-authored-by: Kim Kulling <[email protected]>
ReadChunk() pushed _pos + sz onto the chunk stack using an unvalidated, attacker-controlled size. As a result ChunkSize() (computed as _stack.back() - _pos) could either report a value far larger than the remaining file, or underflow to a huge size_t when a nested chunk overran its parent. The element counts derived from ChunkSize() in ReadVRTS() and ReadTRIS() then drove unbounded _vertices.resize() / new aiFace[] allocations on crafted .b3d input. Validate each chunk's extent at the ReadChunk() chokepoint (it must fit within the file and within its enclosing chunk) and make ChunkSize() underflow-safe, hardening every downstream chunk consumer at once. Co-authored-by: Kim Kulling <[email protected]>



Problem
B3DImporter::ReadChunk()pushed_pos + szonto the chunk stack withsztaken directly from the file and never validated.ChunkSize()returns_stack.back() - _pos, so a crafted.b3dcan make it either report a value far larger than the remaining buffer (oversized chunk) or underflow to a near-SIZE_MAXvalue when a nested chunk's end exceeds its parent's (afterExitChunk()advances_pospast the outer chunk end).The element counts derived from
ChunkSize()then drive unbounded allocations:ReadVRTS():n_verts = ChunkSize() / sz; _vertices.resize(v0 + n_verts);ReadTRIS():n_tris = ChunkSize() / 12; new aiFace[n_tris];so a small malformed file triggers a wild allocation / OOM. (The per-field reads are already bounds-checked, so this is an allocation/DoS issue rather than an out-of-bounds read.)
Fix
Harden the two chunk-model chokepoints rather than each consumer:
ReadChunk()now validates that each chunk lies within the file and within its enclosing chunk before pushing its end offset.ChunkSize()is made underflow-safe.This caps every
ChunkSize()-derived count at the remaining file size, fixingReadVRTS/ReadTRIS/ReadTEXS/ReadBRUSat the root. No behavioral change for well-formed files — a conformant chunk never exceeds its parent or the file.Summary by CodeRabbit
Bug Fixes