Skip to content

MDC: Fix heap OOB read by validating vertex buffer boundaries - #6438

Merged
kimkulling merged 1 commit into
assimp:masterfrom
ydsa:master
Jan 9, 2026
Merged

kimkulling merged 1 commit into
assimp:masterfrom
ydsa:master

Conversation

@ydsa

@ydsa ydsa commented Jan 8, 2026 •

Copy link
Copy Markdown
Contributor

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

[root@localhost assimp]# ./assimp_fuzzer ./crash-0fde422f1ac8e0ddec2c853e1dae0b1144ff5713 
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 2900513876
INFO: Loaded 1 modules   (7 inline 8-bit counters): 7 [0x564d396608c8, 0x564d396608cf), 
INFO: Loaded 1 PC tables (7 PCs): 7 [0x564d396608d0,0x564d39660940), 
./assimp_fuzzer: Running 1 inputs 1 time(s) each.
Running: ./crash-0fde422f1ac8e0ddec2c853e1dae0b1144ff5713
Executed ./crash-0fde422f1ac8e0ddec2c853e1dae0b1144ff5713 in 2 ms
***
*** NOTE: fuzzing was not performed, you have only
***       executed the target code on a fixed set of inputs.
***
[root@localhost assimp]# 

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation when loading 3D model files to prevent out-of-bounds memory reads.
    • Better handling of malformed or corrupted model data to avoid crashes and fail more safely.
    • Increased stability and clearer failure behavior during model import operations.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 8, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This change adds defensive boundary validation for pcVerts and pcCVerts pointers in the MDC asset loader, verifying they (and required byte ranges) lie within the current surface block and throwing DeadlyImportError on violations.

Changes

Cohort / File(s) Summary
Boundary validation for vertex buffers
code/AssetLib/MDC/MDCLoader.cpp
Inserted checks to ensure pcVerts is within the surface block bounds. Added conditional checks for pcCVerts (when present) to validate pointer and required byte range remain inside the surface block. Both raise DeadlyImportError on failure.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

Bug, Security Risk, Fuzzer

Suggested reviewers

  • kimkulling

Poem

🐰 Boundaries checked with careful hop,

Pointers kept from falling off the top,
No stray bytes will roam or roam too far,
Safe vertices snug where they are,
Hooray for loader peace and calm ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the primary change: adding boundary validation to fix a heap out-of-bounds read vulnerability in the MDC loader.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 pcVerts and 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 + needVertBytes could theoretically overflow if needVertBytes is extremely large. Consider matching the more defensive pattern used for pcCVerts (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 pcCVerts and 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 since pcCVerts was 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

📥 Commits

Reviewing files that changed from the base of the PR and between ac8eac6 and 47685d7.

📒 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]>
@sonarqubecloud

sonarqubecloud Bot commented Jan 8, 2026 •

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
3 New issues
1 Accepted issue

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ulNumVertices is 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

📥 Commits

Reviewing files that changed from the base of the PR and between 47685d7 and 333abd8.

📒 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 kimkulling left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine for me, thanks for the nice work.

@kimkulling
kimkulling merged commit 17318b0 into assimp:master Jan 9, 2026
@kimkulling

Copy link
Copy Markdown
Member

Merged, thanks a lot for your contribution.

@kimkulling kimkulling added MDC Bugs related to the MDC format. Security Risk Bugs that could potentially be security vulnerabilities Fuzzer Bugs found by a fuzzer labels Jan 9, 2026
kimkulling pushed a commit that referenced this pull request Jul 1, 2026
…#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]>
tkluge-fender pushed a commit to cclsoftware/assimp that referenced this pull request Jul 28, 2026
…#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fuzzer Bugs found by a fuzzer MDC Bugs related to the MDC format. Security Risk Bugs that could potentially be security vulnerabilities

Projects

Development

Successfully merging this pull request may close these issues.

2 participants