Repository navigation
MDC: Fix heap OOB read by validating vertex buffer boundaries - #6438
Conversation
📝 WalkthroughWalkthroughThis change adds defensive boundary validation for Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
code/AssetLib/MDC/MDCLoader.cpp (2)
327-334: Boundary validation correctly prevents heap OOB reads.The check successfully validates that
pcVertsand its required buffer stay within the surface block, addressing the CVE by catching malformed frame offsets that weren't validated earlier.♻️ Optional refactor for consistency and overflow safety
The addition
vertBufStart + needVertBytescould theoretically overflow ifneedVertBytesis extremely large. Consider matching the more defensive pattern used forpcCVerts(lines 350-351):- if (vertBufStart < surfStart || vertBufStart + needVertBytes > surfEnd) { + if (vertBufStart < surfStart || vertBufStart >= surfEnd || + needVertBytes > static_cast<size_t>(surfEnd - vertBufStart)) { throw DeadlyImportError("MDCImporter: pcVerts points outside of surface block."); }This pattern avoids potential overflow in the addition and matches the style of the pcCVerts check below.
347-354: Boundary validation correctly prevents heap OOB reads for compressed vertices.The check properly validates that
pcCVertsand its required buffer stay within the surface block. The defensive checking pattern (line 350-351) is robust against potential overflow issues.Minor note: The outer
if (pcCVerts)condition at line 347 is redundant sincepcCVertswas just assigned via pointer arithmetic at lines 344-346 and cannot be null. Consider removing it for clarity, though it's harmless as defensive programming.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
code/AssetLib/MDC/MDCLoader.cpp
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: windows-latest-clang.exe-build-and-test
- GitHub Check: windows-latest-cl.exe-build-and-test
- GitHub Check: ubuntu-latest-clang++-build-and-test
- GitHub Check: ubuntu-latest-g++-build-and-test
- GitHub Check: macos-latest-clang++-build-and-test
- GitHub Check: windows-hunter-latest-cl.exe-build-and-test
- GitHub Check: Fuzzing
- GitHub Check: undefined-behavior-sanitizer
- GitHub Check: adress-sanitizer
…#6168) - Add explicit boundary checks for pcVerts and pcCVerts arrays in MDCImporter. - Prevents heap out-of-bounds reads with malformed or truncated files. - Fixes CVE-2025-5166. Signed-off-by: mapengyuan <[email protected]>
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
code/AssetLib/MDC/MDCLoader.cpp (2)
327-334: Good security fix, but consider integer overflow protection.The boundary check correctly prevents the heap OOB read for typical cases. However, the size calculation on Line 331 could overflow if
ulNumVerticesis very large, potentially bypassing the check.🛡️ Suggested overflow protection
// boundary check for pcVerts auto surfStart = reinterpret_cast<const uint8_t*>(pcSurface); const uint8_t* surfEnd = surfStart + pcSurface->ulOffsetEnd; auto vertBufStart = reinterpret_cast<const uint8_t*>(pcVerts); -const size_t needVertBytes = sizeof(MDC::BaseVertex) * pcSurface->ulNumVertices; +const size_t maxVertices = SIZE_MAX / sizeof(MDC::BaseVertex); +if (pcSurface->ulNumVertices > maxVertices) { + throw DeadlyImportError("MDCImporter: vertex count would overflow size calculation."); +} +const size_t needVertBytes = sizeof(MDC::BaseVertex) * pcSurface->ulNumVertices; if (vertBufStart < surfStart || vertBufStart + needVertBytes > surfEnd) { throw DeadlyImportError("MDCImporter: pcVerts points outside of surface block."); }
347-352: Good security fix with safer overflow handling, but add size calculation protection.The boundary check uses a subtraction-based approach (
surfEnd - cvertBufStart) which is more overflow-safe than addition. However, the size calculation on Line 348 could still overflow.🛡️ Suggested overflow protection
auto cvertBufStart = reinterpret_cast<const uint8_t*>(pcCVerts); -const size_t needCompVertBytes = sizeof(MDC::CompressedVertex) * pcSurface->ulNumVertices; +const size_t maxCompVertices = SIZE_MAX / sizeof(MDC::CompressedVertex); +if (pcSurface->ulNumVertices > maxCompVertices) { + throw DeadlyImportError("MDCImporter: compressed vertex count would overflow size calculation."); +} +const size_t needCompVertBytes = sizeof(MDC::CompressedVertex) * pcSurface->ulNumVertices; if (cvertBufStart < surfStart || cvertBufStart > surfEnd || needCompVertBytes > static_cast<size_t>(surfEnd - cvertBufStart)) { throw DeadlyImportError("MDCImporter: pcCVerts points outside of surface block."); }
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
code/AssetLib/MDC/MDCLoader.cpp
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: undefined-behavior-sanitizer
- GitHub Check: adress-sanitizer
- GitHub Check: ubuntu-latest-clang++-build-and-test
- GitHub Check: ubuntu-latest-g++-build-and-test
- GitHub Check: windows-hunter-latest-cl.exe-build-and-test
- GitHub Check: macos-latest-clang++-build-and-test
- GitHub Check: windows-latest-clang.exe-build-and-test
- GitHub Check: windows-latest-cl.exe-build-and-test
- GitHub Check: Fuzzing
kimkulling
left a comment
There was a problem hiding this comment.
Looks fine for me, thanks for the nice work.
|
Merged, thanks a lot for your contribution. |
…#6438) - Add explicit boundary checks for pcVerts and pcCVerts arrays in MDCImporter. - Prevents heap out-of-bounds reads with malformed or truncated files. - Fixes CVE-2025-5166. Signed-off-by: mapengyuan <[email protected]>
…#6168) (assimp#6438) - Add explicit boundary checks for pcVerts and pcCVerts arrays in MDCImporter. - Prevents heap out-of-bounds reads with malformed or truncated files. - Fixes CVE-2025-5166. Signed-off-by: mapengyuan <[email protected]>

Add explicit boundary checks for pcVerts and pcCVerts arrays in MDCImporter (#6168)
Prevents heap out-of-bounds reads with malformed or truncated files.
Fixes CVE-2025-5166.
Verification
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.