Skip to content

Conversation

@JeremyKuhne
Copy link
Member

@JeremyKuhne JeremyKuhne commented Feb 18, 2025

#12953)

PORTS #12953 - DO NOT SQUASH

Until .NET 5, ComManagedStream (then GPStream) would wrap a non-seekable stream in a MemoryStream using the MemoryStream(Byte[]) constructor. This results in a stream with a position of 0.

dotnet/runtime commit 136527537e6 (Improve perfromance for loading from Stream on Windows (dotnet/corefx#31142), 2018-07-20) updated this logic to instead use CopyTo to populate the wrapping MemoryStream. This results in a stream with a non-zero position.

It seems that this non-zero position causes some issues in downstream code when using Image.FromStream to load .emf and .wmf files, resulting in LoadGdipImageFromStream returning a status of 2 and thus an exception.

Seek the wrapping MemoryStream back to the beginning after copying the source stream into it to prevent this exception.

Microsoft Reviewers: Open in CodeFlow

…otnet#12953)

Until .NET 5, `ComManagedStream` (then `GPStream`) would wrap a
non-seekable stream in a `MemoryStream` using the `MemoryStream(Byte[])`
constructor. This results in a stream with a position of 0.

dotnet/runtime commit 136527537e6 (Improve perfromance for loading from
Stream on Windows (dotnet/corefx#31142), 2018-07-20) updated this logic
to instead use `CopyTo` to populate the wrapping `MemoryStream`. This
results in a stream with a non-zero position.

It seems that this non-zero position causes some issues in downstream
code when using `Image.FromStream` to load `.emf` and `.wmf` files,
resulting in `LoadGdipImageFromStream` returning a status of 2 and thus
an exception.

Seek the wrapping `MemoryStream` back to the beginning after copying the
source stream into it to prevent this exception.

Fixes dotnet#12951
@JeremyKuhne JeremyKuhne added 🚫 * NO-MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) servicing-consider .NET Shiproom label indicating a PR seeks to enter into a branch under Tell-Mode criteria labels Feb 18, 2025
@JeremyKuhne JeremyKuhne requested a review from a team as a code owner February 18, 2025 22:33
@codecov
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.84000%. Comparing base (44f90e2) to head (50d4a08).
Report is 6 commits behind head on release/9.0.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           release/9.0      #12970         +/-   ##
=====================================================
+ Coverage     74.83821%   74.84000%   +0.00178%     
=====================================================
  Files             3022        3022                 
  Lines           630460      630461          +1     
  Branches         46797       46797                 
=====================================================
+ Hits            471825      471837         +12     
+ Misses          155247      155235         -12     
- Partials          3388        3389          +1     
Flag Coverage Δ
Debug 74.84000% <100.00000%> (+0.00178%) ⬆️
integration 18.01512% <0.00000%> (+0.00451%) ⬆️
production 47.87122% <100.00000%> (+0.00404%) ⬆️
test 97.00179% <ø> (ø)
unit 44.88305% <100.00000%> (+0.00159%) ⬆️

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.

@JeremyKuhne JeremyKuhne added servicing-approved .NET Shiproom approved the PR for merge and removed servicing-consider .NET Shiproom label indicating a PR seeks to enter into a branch under Tell-Mode criteria labels Feb 20, 2025
@Tanya-Solyanik Tanya-Solyanik added this to the 9.0.4 milestone Mar 11, 2025
@Tanya-Solyanik Tanya-Solyanik merged commit 34122aa into dotnet:release/9.0 Mar 11, 2025
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

🚫 * NO-MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) servicing-approved .NET Shiproom approved the PR for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants