-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Handle unterminated string data in DataObject #13949
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
base: main
Are you sure you want to change the base?
Conversation
Manually look for the terminator and return empty string if there is no terminator. Throw for bad HGLOBALs. Needed to add some more code for testing nested private generic classes.
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.
Pull Request Overview
This PR handles unterminated string data in DataObject by implementing proper validation and error handling for HGLOBAL string reading operations. The changes ensure that malformed clipboard data returns empty strings instead of causing exceptions, and add proper error handling for invalid HGLOBAL handles.
- Enhanced string reading methods to validate null terminators and handle malformed data gracefully
- Added comprehensive test coverage for the new string handling logic
- Extended test utilities to support testing nested private generic classes
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
Composition.NativeToManagedAdapter.cs | Implemented robust string reading with null terminator validation and error handling |
NativeToManagedAdapterTests.cs | Added test cases for invalid HGLOBAL, unterminated strings, and proper termination scenarios |
TestAccessors.cs | Added documentation for testing nested private generic types |
TestAccessor.cs | Enhanced exception unwrapping for better test debugging |
ReflectionHelper.cs | Added utility method to handle nested generic type instantiation |
...em.Private.Windows.Core/src/System/Private/Windows/Ole/Composition.NativeToManagedAdapter.cs
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #13949 +/- ##
====================================================
+ Coverage 52.01464% 77.14239% +25.12775%
====================================================
Files 2064 3276 +1212
Lines 287892 645155 +357263
Branches 42113 47714 +5601
====================================================
+ Hits 149746 497688 +347942
- Misses 135253 143777 +8524
- Partials 2893 3690 +797
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
try | ||
{ | ||
int size = (int)PInvokeCore.GlobalSize(hglobal); | ||
int size = checked((int)PInvokeCore.GlobalSize(hglobal)); |
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.
Do we throw here for size == 0
?
void* buffer = PInvokeCore.GlobalLock(hglobal); | ||
if (buffer is null) | ||
{ | ||
throw new ExternalException(SR.ExternalException, (int)HRESULT.E_OUTOFMEMORY); |
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.
Should we update the ExternalException
to Win32Exception
?
Manually look for the terminator and return empty string if there is no terminator. Throw for bad HGLOBALs.
Needed to add some more code for testing nested private generic classes.
Fixes #13929
Microsoft Reviewers: Open in CodeFlow