-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Throw an exception when passing strings by-value as out parameters. #21513
Throw an exception when passing strings by-value as out parameters. #21513
Conversation
@jkoritzinsky something strange happened to the tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTest.cs file, git now thinks it is binary file for some reason and doesn't show a diff. |
Probably an encoding issue. I'll go fix that. |
Fixed. It was encoded as UTF-16 LE which GitHub has a habit of thinking is binary. Changed it to UTF-8. |
GitHub still thinks it is binary. Ok, I've just fetched the contents of the file and diffed it locally. |
The linux-musl x64 build now fails:
That's because you have added the SupportsArgumentMarshal method with |
Will do. |
tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestNative.cpp
Outdated
Show resolved
Hide resolved
tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestNative.cpp
Outdated
Show resolved
Hide resolved
Marshal_In was copied back into existence from Marshal_InOut. Clean it up a bit.
…insky/coreclr into block-string-byvalue-out
@dotnet-bot test this please. |
@dotnet-bot test this please |
It looks like some portions of See: https://github.com/dotnet/corefx/blob/784bd1b648dd5a69e10d6c22067c42088aaca90b/src/System.Management/src/System/Management/ManagementPath.cs#L324-L325 and https://github.com/dotnet/corefx/blob/fcea0a593a8b198d7ae741dcb80345ea2b129fe0/src/System.Management/src/System/Management/InteropClasses/WMIInterop.cs#L966 |
…t uninitialized).
…-string-byvalue-out
…-string-byvalue-out
@dotnet-bot test Ubuntu arm Cross Checked Innerloop Build and Test |
…-string-byvalue-out
@dotnet-bot test Ubuntu x64 Checked Innerloop Build and Test (Jit - TieredCompilation=0) |
@AaronRobinsonMSFT I've just found this PR from last December was not merged in yet. Since I am not familiar with the marshalling code, I don't feel confident enough to approve the change. Could you please do that? |
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.
Please update the docs about P/Invokes and root cause the Linux failure, otherwise LGTM.
@AaronRobinsonMSFT I've already updated the docs to advise to not do this, but I'll go an add an update to that saying that it is disallowed in .NET Core 3.0+. |
@dotnet-bot test this please |
@jkoritzinsky the Linux-musl has a build break due to the source of the test. It is strange that it doesn't fail for non-MUSL Linux, as it complains about the wcslen and wmemcmp argument mismatch (it says the functions expect |
I am trying to run the build on my local Alpine to see if I can find the real culprit. |
It is really weird - I can build coreclr with your change on my local Alpine just fine and the affected file is really being compiled. I'll retry the leg here. |
@dotnet-bot test Linux-musl x64 Debug Build please |
1 similar comment
@dotnet-bot test Linux-musl x64 Debug Build please |
tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestNative.cpp
Outdated
Show resolved
Hide resolved
tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestNative.cpp
Outdated
Show resolved
Hide resolved
Co-Authored-By: jkoritzinsky <jkoritzinsky@gmail.com>
…otnet/coreclr#21513) * Throw an exception when passing strings by-value as out parameters. * Fix encoding * Don't use override in this PR. * Clean up Marshal_In Marshal_In was copied back into existence from Marshal_InOut. Clean it up a bit. * Remove extraneous whitespace. * Fix failing test. * Remove out attribute in COM string tests. * Add back attribute and check for exception thow in COM tests. * Add block comment to explain the implementation of Reverse_LPWStr_OutAttr in the NETServer. * Only throw in a CLR->Native marshalling situation. * Fix asserts from changed code-paths used in ILWSTRMarshaler. * Add comment and explicitly load in a null value (instead of leaving it uninitialized). * Apply suggestions from code review Co-Authored-By: jkoritzinsky <jkoritzinsky@gmail.com> Co-authored-by: Jan Vorlicek <janvorli@microsoft.com> Commit migrated from dotnet/coreclr@2f88f32
Block users from adding an
[Out]
attribute on strings and modifying them in place to avoid causing crashes with unloadability and string interning. Instead of allowing it, we'll throw aMarshalDirectiveException
. Fixes #21506.Blocked on dotnet/corefx#34091