Skip to content

Conversation

JeremyKuhne
Copy link
Member

@JeremyKuhne JeremyKuhne commented Oct 9, 2025

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

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.
@JeremyKuhne JeremyKuhne requested a review from a team as a code owner October 9, 2025 21:15
@JeremyKuhne JeremyKuhne requested review from Copilot and removed request for a team October 9, 2025 21:15
@JeremyKuhne JeremyKuhne added area-Clipboard Issues related to Clipboard and removed area-Infrastructure labels Oct 9, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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

Copy link

codecov bot commented Oct 10, 2025

Codecov Report

❌ Patch coverage is 73.21429% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.14239%. Comparing base (be8f5b0) to head (a7c5f76).
⚠️ Report is 19 commits behind head on main.

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     
Flag Coverage Δ
Debug 77.14239% <73.21429%> (+25.12775%) ⬆️
integration 18.99060% <3.22581%> (+0.00049%) ⬆️
production 51.99919% <77.41935%> (-0.01546%) ⬇️
test 97.40650% <68.00000%> (?)
unit 49.44428% <77.41935%> (+0.00907%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

try
{
int size = (int)PInvokeCore.GlobalSize(hglobal);
int size = checked((int)PInvokeCore.GlobalSize(hglobal));
Copy link
Member

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);
Copy link
Member

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Clipboard Issues related to Clipboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clipboard.GetData performs improper validation

2 participants