-
-
Notifications
You must be signed in to change notification settings - Fork 186
Fix corruption in virtual methods cache table #3245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughDefensive programming enhancements added to Cache.cpp, including DEBUG diagnostics to detect memory overlaps in VirtualMethodTable structure initialization and runtime safety checks in the FindVirtualMethod hash lookup loop to validate indices, repair corrupted hash chains, and handle invalid payload entries. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ 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 |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/CLR/Core/Cache.cpp (1)
199-250: Good defensive diagnostics; consider format specifier safety on 64-bit.The diagnostic output is excellent for debugging memory layout issues. However, casting
uintptr_ttounsigned intand using%08Xwill truncate addresses on 64-bit platforms.Consider using
%por platform-appropriate format specifiers:CLR_Debug::Printf( - "m_entries: 0x%08X - 0x%08X (%u bytes)\r\n", - (unsigned int)entries_start, - (unsigned int)entries_end, + "m_entries: %p - %p (%u bytes)\r\n", + (void*)entries_start, + (void*)entries_end, (unsigned int)(entries_end - entries_start));Apply similar changes to lines 223-232.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/CLR/Core/Cache.cpp(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/CLR/Core/Cache.cpp (3)
src/CLR/Diagnostics/Info.cpp (2)
Printf(256-269)Printf(256-256)src/CLR/Core/TypeSystem.cpp (2)
Link(6563-6580)Link(6563-6563)src/CLR/Core/CLR_RT_RuntimeMemory.cpp (6)
LinkArraySize(111-114)LinkArraySize(111-111)LinkMRUArraySize(115-118)LinkMRUArraySize(115-115)PayloadArraySize(119-122)PayloadArraySize(119-119)
⏰ 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). (6)
- GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets MXCHIP_AZ3166)
- GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALX)
- GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALTHREE)
- GitHub Check: nf-interpreter (Check_Code_Style)
- GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
- GitHub Check: nf-interpreter (Check_Build_Options)
🔇 Additional comments (4)
src/CLR/Core/Cache.cpp (4)
362-371: Excellent bounds validation to prevent memory corruption.This runtime safety check validates the index before dereferencing arrays, addressing the memory access exceptions mentioned in the PR objectives. The repair logic correctly resets the corrupted hash chain and treats the lookup as a cache miss.
375-375: Good defensive assertion for payload index bounds.This assertion ensures that indices in the hash chain fall within the payload array bounds, catching logic errors in debug builds.
379-382: Good addition of braces for clarity.Adding braces around single-statement blocks improves consistency and prevents future bugs.
Also applies to: 384-387, 395-398
406-408: Critical fix: Initialize entry links before use.This initialization is essential to prevent memory corruption. Without it,
MoveEntryToTopat line 419 would use uninitializedm_nextandm_prevvalues, potentially causing the crashes described in the PR objectives.
1f30b77 to
5395f0a
Compare
5395f0a to
ab452c8
Compare
|
Unit tests failing because of features missing in EE and type engine. Addressed in #3242 . Merging anyway. |
Description
Motivation and Context
How Has This Been Tested?
Screenshots
Types of changes
Checklist
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.