Fix MarshalArrayAsParam/AsLPArray/AsLPArrayTest test#126443
Fix MarshalArrayAsParam/AsLPArray/AsLPArrayTest test#126443MichalStrehovsky merged 4 commits intodotnet:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a NativeAOT P/Invoke marshalling bug for [Out, MarshalAs(UnmanagedType.LPArray)] array parameters (notably string[]), where the native buffer was allocated but left uninitialized, allowing native code to free garbage pointers and corrupt the heap.
Changes:
- Zero-initialize the newly allocated native LPArray buffer for out-only (
!In) array parameters in the IL marshaller. - Re-enable the previously skipped NativeAOT test for
AsLPArrayTestnow that the underlying issue is fixed.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/tests/Interop/PInvoke/Array/MarshalArrayAsParam/AsLPArray/AsLPArrayTest.cs | Removes the NativeAOT ActiveIssue skip so the regression scenario is exercised again. |
| src/coreclr/tools/Common/TypeSystem/Interop/IL/Marshaller.cs | Ensures out-only LPArray allocations are zeroed via initblk, preventing invalid frees of uninitialized pointer slots. |
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Removed ActiveIssue attributes related to VARIANT marshalling and updated issue references.
|
We had one more test disabled on this. The disablement also didn't make sense and was doubly disabled (looks like we ended up with both in some bulk updates). If there is any variant marshalling and the test fails, we'll just condition it correctly. (Cc @jkoritzinsky) |
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/ba-g GC test failure was fixed in #126440 |
When marshalling an
[Out, MarshalAs(UnmanagedType.LPArray)] string[]parameter, the marshaller allocates a native buffer but skips initialization (TransformManagedToNativeis skipped for out-only parameters). Native callees can attempt to free those uninitialized pointers and cause heap corruption.Fixes #81674.