Skip to content

Fix app crash when loading large URI images - #38204

Merged
kubaflo merged 2 commits into
inflight/currentfrom
jonathanpeppers-limit-uri-image-downloads
Sep 4, 2026
Merged

kubaflo merged 2 commits into
inflight/currentfrom
jonathanpeppers-limit-uri-image-downloads

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

Limit URI image response buffering to 50 MiB so unexpectedly large images fail to load instead of crashing the app. Allow apps to override the limit through MSBuild or AppContext.

The new setting and its default are documented in docs/design/FeatureSwitches.md.

Issues Fixed

N/A

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Generalizes the existing Darc-based official release pipeline so it can
publish shipping NuGet packages from allowlisted non-workload
repositories, initially `dotnet/android-libraries`, while preserving the
existing MAUI workload-release path.

- Keeps the existing free-text repository and commit inputs.
- Infers workload behavior for `dotnet/android`, `dotnet/macios`, and
`dotnet/maui`.
- Preserves the existing first-match BAR resolution behavior for all
repositories, then validates the resolved repository and gathers using
the dynamically returned BAR build ID.
- Keeps workload gathering, workload-set promotion, pack-before-manifest
ordering, approvals, and publishing behavior isolated from the
non-workload path.
- Gathers only shipping NuGet assets and rejects malformed packages,
duplicate filenames, duplicate ID/version identities, unexpected
packages, and workload manifests on non-workload releases.
- Supports include/exclude package filters for both workload and
non-workload releases.
- Filters exact ID/version pairs already on NuGet.org during preparation
and again immediately before publishing, preventing reruns and packages
published between those phases from causing HTTP 409 conflicts.
- Supports repeating the same non-workload BAR release after partial
publication: Darc may no longer download assets whose BAR location moved
to NuGet.org, so missing selected assets are accepted only when their
exact identity is confirmed on NuGet.org. Other missing or unavailable
packages fail closed.
- Publishes the exact selected and staged package lists as the
`NuGetReleaseAudit` artifact before manual approval.
- Uses the existing `1ES.PublishNuget@1` task and `nuget.org
(dotnetframework)` service connection, then verifies every expected
package on NuGet.org.
- Supports a non-mutating dry run with `pushPackages: false`.

### Dry-run inputs

```yaml
ghOwner: dotnet
ghRepo: android-libraries
commitHash: <ANDROID_LIBRARIES_COMMIT_WITH_BAR_BUILD>
pushWorkloadSet: false
pushNugetOrg: true
pushPackages: false
```

Queue `dotnet-maui-release` against this PR branch after it appears in
the internal `dotnet-maui` mirror. The run performs BAR resolution,
gathering, package validation/filtering, and audit artifact publication
without promotion or NuGet publishing.

### External setup

Before enabling a real push, release owners must verify that the
existing `nuget.org (dotnetframework)` service connection owns every
package ID in the audit artifact and has sufficient scope/quota.
Android-libraries BAR builds contain per-build deltas rather than the
union of channel assets, so each pending BAR build must be released in
commit order.

### Validation

- [Successful `dotnet/android-libraries` NuGet.org release
run](https://dev.azure.com/dnceng/internal/_build/results?buildId=3063121&view=results):
BAR resolution, gathering, filtering, audit publication, package push,
and NuGet.org verification all succeeded.
- The overall build is `partiallySucceeded` only because 1ES production
branch/source validation reported non-blocking errors for running the
test from this PR branch instead of an approved production branch.
- Focused release pipeline and NuGet availability Pester suites.
- YAML parsing and whitespace validation.

### Issues Fixed

N/A

---------

Copilot-Session: 2933e733-3bed-4524-ae14-f7ad1c7959e6
Limit URI image response buffering to 50 MiB so unexpectedly large images fail to load instead of crashing the app. Allow apps to override the limit through MSBuild or AppContext.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 60d18542-ecd9-47f8-a36c-f895a934522c
Copilot AI lite review requested due to automatic review settings September 4, 2026 13:17
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38204

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38204"

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A couple of small but concrete issues were found (a misleading error message for out-of-range numeric values and a missing Trim setting on the new runtime host configuration entry).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR prevents crashes/OOMs when UriImageSource downloads unexpectedly large responses by setting a 50 MiB default HttpClient.MaxResponseContentBufferSize, while allowing apps to override the limit via an MSBuild property (runtimeconfig/AppContext) or directly via AppContext.

Changes:

  • Set HttpClient.MaxResponseContentBufferSize for UriImageSource downloads, with a default of 50 MiB and AppContext-based override parsing/validation.
  • Add unit tests covering default behavior, configurability, and invalid configurations.
  • Document the new runtime setting and MSBuild property in FeatureSwitches.md, and wire the MSBuild property into RuntimeHostConfigurationOption.
File summaries
File Description
src/Controls/src/Core/UriImageSource.cs Enforces a configurable max response buffer size for URI image downloads and adds AppContext parsing/validation.
src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs Adds tests for default/configured/invalid max buffer size values.
src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets Exposes an MSBuild property to set the runtimeconfig/AppContext value transitively.
docs/design/FeatureSwitches.md Documents the new runtime setting/property and default value.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread src/Controls/src/Core/UriImageSource.cs Resolved
@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Sep 4, 2026

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Review — 1 findings

See inline comments for details.

}
}

[Fact]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 AI-Generated Review (multi-model)

[major] Regression Prevention and Test Coverage — The new tests only validate AppContext parsing via GetMaxResponseContentBufferSize() and do not exercise the actual download path (DownloadStreamAsync -> StreamWrapper.GetStreamAsync) with an oversized HTTP response. Concrete regression risk: if client.MaxResponseContentBufferSize is removed/bypassed later, the original large-response buffering failure can return while these tests still pass.

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review Summary

@jonathanpeppers — new AI review results are available based on commit 02443bd.

Gate Passed Confidence Low Platform Android


🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix

Gate Result: ✅ PASSED

Platform: ANDROID · Base: main · Merge base: f05f0f39

✅ Verified (new API / feature) — this PR adds new API and a test that references it in the same project, so reverting the fix un-compiles the test: there is no valid "fails without the fix" baseline to establish (a compile-coupled baseline). The gate instead verified the fix by a clean build + pass with the fix, so this is a real PASS rather than a non-committal INCONCLUSIVE.

Test Without Fix (expect FAIL) With Fix (expect PASS)
🧪 UriImageSourceTests UriImageSourceTests 🛠️ BUILD ERROR ✅ PASS — 82s
🔴 Without fix — 🧪 UriImageSourceTests: 🛠️ BUILD ERROR · 92s

Error-relevant lines (filtered from the build log):

/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs(113,58): error CS0117: 'UriImageSource' does not contain a definition for 'MaxResponseContentBufferSizeAppContextKey' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs(117,39): error CS0117: 'UriImageSource' does not contain a definition for 'MaxResponseContentBufferSizeAppContextKey' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs(119,51): error CS0117: 'UriImageSource' does not contain a definition for 'GetMaxResponseContentBufferSize' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs(123,39): error CS0117: 'UriImageSource' does not contain a definition for 'MaxResponseContentBufferSizeAppContextKey' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs(130,58): error CS0117: 'UriImageSource' does not contain a definition for 'MaxResponseContentBufferSizeAppContextKey' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs(136,40): error CS0117: 'UriImageSource' does not contain a definition for 'MaxResponseContentBufferSizeAppContextKey' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs(138,68): error CS0117: 'UriImageSource' does not contain a definition for 'GetMaxResponseContentBufferSize' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs(143,39): error CS0117: 'UriImageSource' does not contain a definition for 'MaxResponseContentBufferSizeAppContextKey' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs(154,58): error CS0117: 'UriImageSource' does not contain a definition for 'MaxResponseContentBufferSizeAppContextKey' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs(158,39): error CS0117: 'UriImageSource' does not contain a definition for 'MaxResponseContentBufferSizeAppContextKey' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs(160,67): error CS0117: 'UriImageSource' does not contain a definition for 'GetMaxResponseContentBufferSize' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs(164,39): error CS0117: 'UriImageSource' does not contain a definition for 'MaxResponseContentBufferSizeAppContextKey' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
🟢 With fix — 🧪 UriImageSourceTests: PASS ✅ · 82s

(no coded error found; showing last 1200 chars)

mStream
  Skipped ConcurrentCallsOnSameUriAreQueued [1 ms]
  Passed MaxResponseContentBufferSizeDefaultsTo50MiB [7 ms]
  Skipped LoadImageFromStream [1 ms]
  Passed MaxResponseContentBufferSizeRejectsInvalidValues(configuredValue: "invalid") [< 1 ms]
  Passed MaxResponseContentBufferSizeRejectsInvalidValues(configuredValue: 0) [< 1 ms]
  Passed MaxResponseContentBufferSizeRejectsInvalidValues(configuredValue: -1) [< 1 ms]
  Passed MaxResponseContentBufferSizeRejectsInvalidValues(configuredValue: 2147483648) [< 1 ms]
  Passed UrlHashKeyAreTheSame [1 ms]
  Passed NullUriDoesNotCrash [1 ms]
[xUnit.net 00:00:01.31]     SecondCallLoadFromCache [SKIP]
[xUnit.net 00:00:01.31]       SecondCallLoadFromCache
[xUnit.net 00:00:01.31]     DoNotKeepFailedRetrieveInCache [SKIP]
[xUnit.net 00:00:01.31]       DoNotKeepFailedRetrieveInCache
[xUnit.net 00:00:01.31]   Finished:    Microsoft.Maui.Controls.Core.UnitTests
  Passed MaxResponseContentBufferSizeCanBeConfigured [< 1 ms]
  Skipped SecondCallLoadFromCache [1 ms]
  Passed UrlHashKeyAreNotTheSame [< 1 ms]
  Skipped DoNotKeepFailedRetrieveInCache [1 ms]
Test Run Successful.
Total tests: 13
     Passed: 9
    Skipped: 4
 Total time: 1.9140 Seconds

⚠️ Failure Details

  • 🛠️ UriImageSourceTests without fix: build failed before tests could run
    • /home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs(113,58): error CS0117: 'UriImageSource' does not contain a definition for 'MaxResponseContentBufferSizeAppContextKey' [/hom...
📁 Fix files reverted (2 files)
  • src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets
  • src/Controls/src/Core/UriImageSource.cs

📋 Pre-Flight — Context & Validation

Issue: None linked
PR: #38204 - Fix app crash when loading large URI images
Platforms Affected: Shared UriImageSource path (all platforms); requested candidate validation platform: Android
Files Changed: 2 implementation/configuration, 1 test, 1 documentation

Problem and Existing Fix

UriImageSource.DownloadStreamAsync creates an HttpClient and delegates to
StreamWrapper.GetStreamAsync. That helper uses the default
HttpCompletionOption.ResponseContentRead, so the response is buffered before
the stream is returned. An unexpectedly large response can therefore consume
enough memory to crash the app.

The PR limits HttpClient.MaxResponseContentBufferSize to 50 MiB before the
request. It adds an AppContext setting
Microsoft.Maui.Controls.UriImageSource.MaxResponseContentBufferSize, exposes
that setting through the
MauiUriImageSourceMaxResponseContentBufferSize MSBuild property, validates
integer/string configuration values, documents the setting, and adds three
focused unit-test methods covering the default, valid overrides, and invalid
values.

Changed Files

  • src/Controls/src/Core/UriImageSource.cs
  • src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets
  • src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs
  • docs/design/FeatureSwitches.md

Review Context

  • No issue is linked and the PR description supplies no external reproduction.
  • The only inline feedback questioned Trim="true" on the non-boolean runtime
    setting and the invalid-value error wording; the author replied that trimming
    applies to boolean switches and that the separate range error is intentional.
  • Per the STEP 5a hard contract, no separate expert-review agent was launched.
    Each candidate must perform only the try-fix skill's inline expert self-review.
  • Candidate approaches must not repeat the PR's mechanism of assigning
    HttpClient.MaxResponseContentBufferSize.

Test Contract

Detected primary test:

dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "UriImageSourceTests"

This is the gate-detected primary test and runs the complete
UriImageSourceTests class: 13 cases were discovered, with 9 passing and 4
pre-existing skipped cases. No additional mandatory regression tests were
supplied in the STEP 5a request. The gate must not be rerun or overwritten.

Gate Result

Gate PASSED. The without-fix side is compile-coupled because the retained tests
reference the PR's new internal members, so it produced the expected build
errors; the complete UriImageSourceTests class built and passed with the fix.

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #38204 Set HttpClient.MaxResponseContentBufferSize from a 50 MiB AppContext/MSBuild-configurable limit Gate PASS UriImageSource.cs, Controls targets, tests, docs Original PR mechanism; alternatives must differ

🔬 Code Review — Deep Analysis

Code Review — PR #38204

Independent Assessment

What this changes: The shared UriImageSource download path now caps HttpClient's eager response-content buffering at 50 MiB by default. An AppContext value, optionally generated from the MauiUriImageSourceMaxResponseContentBufferSize MSBuild property, can replace that limit after strict integer and positive-range validation.

Inferred motivation: StreamWrapper.GetStreamAsync calls HttpClient.GetAsync with the default ResponseContentRead completion mode, so the entire response is buffered before an image stream is returned. Bounding that buffer prevents an unexpectedly large response from consuming memory until the app crashes.

Approach assessment: Assigning HttpClient.MaxResponseContentBufferSize before the request is a focused and sound enforcement point for the existing eager-buffering design. It covers declared, missing, chunked, and inaccurate Content-Length values because HttpClient enforces the limit while buffering actual content.

Reconciliation with PR Narrative

Author claims: Large URI image responses should fail to load rather than crash the app, with a 50 MiB default and MSBuild/AppContext override.

Agreement/disagreement: The implementation matches that claim. The configuration-only unit tests do not, however, prove that an oversized response is rejected by the real download path.

Prior Review Reconciliation

No prior ❌ Error findings were found across review bodies, inline comments, and issue comments. Two prior Copilot suggestions remain non-blocking: Trim="true" is intended for boolean feature switches rather than this numeric runtime setting, and the parsing/range branches already provide distinct diagnostics for malformed versus supported numeric types.

Blast Radius Assessment

  • Runs for all instances: Yes. Every UriImageSource download uses the new default or configured cap.
  • Startup impact: No. Configuration is read only when a URI image download creates its HttpClient.
  • Static/shared state: The AppContext setting is process-wide, but the PR adds no mutable MAUI static field.
  • Adjacent image scenarios: Responses at or below the limit retain the existing buffered-stream path; absent or dishonest length metadata cannot bypass HttpClient's actual buffered-byte limit; cancellation and non-success handling remain in the existing call chain.

CI Status

  • Required-check result: unavailable because gh is unauthenticated.
  • Classification: GitHub required-check coverage is undetermined. The trusted Gate passed the focused UriImageSourceTests, but its without-fix result was compile-coupled and did not reproduce an oversized download.
  • Action taken: confidence capped at low; Gate verification was not rerun.

Findings

⚠️ Warning — Regression test does not exercise oversized response enforcement

src/Controls/tests/Core.UnitTests/UriImageSourceTests.cs:127 adds tests for GetMaxResponseContentBufferSize() parsing only. None sends an oversized HTTP response through DownloadStreamAsync and StreamWrapper.GetStreamAsync. Removing or bypassing the client.MaxResponseContentBufferSize assignment would therefore reintroduce the original failure while every submitted test remained green. Add a focused local-HTTP regression test that sets a small limit, serves a larger body, invokes IStreamImageSource.GetStreamAsync, and verifies loading fails without exposing the response stream.

Failure-Mode Probing

  • Oversized response with a valid Content-Length: HttpClient.GetAsync buffers and throws once the configured maximum is exceeded; DownloadStreamAsync logs and returns null.
  • Oversized chunked response or missing/inaccurate Content-Length: enforcement counts buffered content rather than trusting metadata, so the same cap applies.
  • Invalid process-wide setting: parsing fails before the request; the existing download catch logs the configuration error and returns null.
  • Concurrent test execution: the submitted tests restore the AppContext value in finally, but only helper parsing is exercised; a real download regression test must use the same restoration discipline.

External Output Contract

Not applicable.

Verdict: NEEDS_CHANGES

Confidence: low
Summary: The production mechanism is focused and appears correct, but the bug fix lacks a regression test of its actual failure path. The trusted Gate only proves the helper tests compile and pass, while required GitHub check status is unavailable.


🛠️ Try-Fix — Analysis & Comparison

Try-Fix Candidates

Both permitted attempts reached the same mandatory baseline safety blocker
before implementation. The approaches below are bounded design candidates, not
validated replacement patches.

Candidate 1 - ResponseHeadersRead with Content-Length Guard

Model: gpt-5.3-codex

Approach: Replace the default response-content buffering path with
HttpCompletionOption.ResponseHeadersRead, then reject a response whose
declared Content-Length exceeds the configured limit before exposing its body
stream.

Difference from the PR: The PR allows the default buffered request to run
and constrains that buffer through HttpClient.MaxResponseContentBufferSize.
This candidate instead proposed preventing eager body buffering and enforcing
the policy from response metadata before body access.

Result: BLOCKED

Files changed: None

Test: Not run. The mandatory baseline command rejected the pre-existing
dirty working directory and did not create .github/.baseline-state.json.
Without a RevertedFiles allow-list, the try-fix contract prohibited edits and
testing. The required restore command completed with No baseline state found.

Failure analysis: The candidate could not be implemented safely because the
repository contains extensive unrelated tracked and untracked changes. This is
an environment/baseline-boundary blocker, not an empirical result about the
proposed mechanism. A Content-Length-only design would also need to account
for missing or dishonest lengths before it could be considered complete.

Self-review: 0 findings; there was no candidate diff to review.

Diff: Empty.

Candidate 2 - Actual-Byte Bounded Copy

Model: gpt-5.6-sol

Approach: Read the response body in fixed-size chunks while counting the
actual bytes transferred, stop once the configured limit would be exceeded,
and expose only a fully bounded result.

Difference from the PR and Candidate 1: The PR delegates enforcement to
HttpClient.MaxResponseContentBufferSize, while Candidate 1 proposed trusting
the declared Content-Length before body access. Candidate 2 would enforce the
limit against bytes actually received, so missing, chunked, or dishonest
content lengths cannot bypass it.

Result: BLOCKED

Files changed: None

Test: Not run. Baseline establishment again rejected the pre-existing dirty
working directory and created no .github/.baseline-state.json, so no safe
RevertedFiles modification boundary existed. The required restore command
completed with No baseline state found and Restored False, which is the
expected no-state outcome when no attempt edits were made.

Failure analysis: This candidate was not empirically evaluated. Bypassing
the baseline safety boundary would risk overwriting unrelated changes, so the
attempt correctly stopped before implementation. If evaluated later, the
bounded-copy design must preserve cancellation, response disposal, stream
position, and avoid allocating beyond the configured cap.

Self-review: 0 findings; the inline expert self-review had no candidate diff
to inspect.

Diff: Empty.


📝 PR Finalize — Recommended Title & Description

Assessment: ✏️ Recommend updating — the current metadata is accurate, but the title omits the shared platform scope and UriImageSource component, while the description does not explain the eager-buffering root cause or name the configuration settings.

Recommended title

[All] UriImageSource: Limit response buffering to prevent app crashes

Recommended description

### Description of Change

`UriImageSource` uses `HttpClient.GetAsync` with the default response-content completion mode, which buffers the response before returning the image stream. An unexpectedly large response can therefore consume enough memory to crash the app.

Limit URI image response buffering to 50 MiB by default so oversized images fail to load instead of crashing the app. Apps can override the limit with the `MauiUriImageSourceMaxResponseContentBufferSize` MSBuild property or the `Microsoft.Maui.Controls.UriImageSource.MaxResponseContentBufferSize` AppContext setting.

The setting, its default, and an MSBuild configuration example are documented in `docs/design/FeatureSwitches.md`. Unit tests cover the default, valid integer/string overrides, and invalid values.

This change is in the shared `UriImageSource` download path and therefore applies across platforms.

### Issues Fixed

N/A

🏁 Report — Final Recommendation

⚠️ Final Recommendation: REQUEST CHANGES

Winner

pr-plus-reviewer is the single winning candidate. It preserves the submitted PR's focused and sound production fix, then closes the expert reviewer's only actionable gap with a regression test that executes the real oversized-response download path. Its required targeted validation passed.

Comparative Ranking

Rank Candidate Implementation Regression evidence Result Assessment
1 pr-plus-reviewer Raw PR fix plus a loopback oversized-response test Focused command passed: 10 passed, 4 pre-existing skipped, 0 failed PASS Best balance of minimal production change and direct protection against disconnecting the configured limit from HttpClient.
2 pr Sets a configurable 50 MiB HttpClient.MaxResponseContentBufferSize on the existing eager-buffering path Trusted Gate passed, but the without-fix side was compile-coupled and all submitted tests only exercise configuration parsing PASS with coverage gap Production mechanism is correct and handles actual buffered bytes regardless of response length metadata, but no test executes the failure scenario.
3 try-fix-2 Proposed an actual-byte bounded copy No patch and no test run because baseline establishment was blocked BLOCKED Conceptually enforces an observed-byte limit, but remains unimplemented and would need to preserve cancellation, disposal, stream semantics, and bounded allocation.
4 try-fix-1 Proposed ResponseHeadersRead plus a Content-Length guard No patch and no test run because baseline establishment was blocked BLOCKED Incomplete as described because missing, chunked, or dishonest Content-Length values can bypass a metadata-only guard.

No candidate failed a regression test. The two STEP 5a alternatives rank below both passing PR-based candidates because they contain no implementation or empirical result.

Expert Review Findings

The single expert pass found one major regression-prevention issue on the submitted diff: UriImageSourceTests validates the AppContext parser but never downloads an oversized response. The production line assigning client.MaxResponseContentBufferSize could therefore be removed or bypassed while every submitted test stayed green. No blocking production-code error was found.

Prior review comments about adding Trim="true" and changing the malformed-value message do not establish defects. Trim is used by the surrounding boolean feature switches and is not appropriate evidence of whitespace handling for a numeric runtime option; the implementation intentionally distinguishes unsupported/malformed values from supported numeric values outside the valid positive int range.

Why pr-plus-reviewer Wins

The reviewer refinement is surgical: it changes only UriImageSourceTests, exercises IStreamImageSource.GetStreamAsync against a deterministic loopback response one byte over a small configured cap, restores the process-wide AppContext value in finally, and leaves the submitted production/configuration/docs design intact. The exact required command passed from the prescribed sandbox.

Because the winner contains a change not present in the submitted PR HEAD, the submitted PR should be updated before approval.


📱 UI Tests — Button,Label,Layout

Detected UI test categories: Button,Label,Layout

✅ Deep UI tests — 360 passed, 0 failed, 7 skipped across 3 categories on platform-pool agent (replaces in-process counts above).

🧪 UI Test Execution Results (deep, platform pool)

Category Tests Snapshot diffs
Button 71/73 (2 skipped) ✓ —
Label 97/99 (2 skipped) ✓ —
Layout 192/195 (3 skipped) ✓ —
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)

🧭 Next Steps — reviewer changes required

The reviewer-enhanced candidate identified changes that are not yet in the submitted PR.

Why: The submitted buffering-limit mechanism is focused and sound, and pr-plus-reviewer preserves it while adding the missing end-to-end oversized-response regression test. The exact targeted UriImageSourceTests command passed in the prescribed candidate sandbox.

Address the actionable findings in this review before merging.

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-fix-win AI found a better alternative fix than the PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) and removed s/agent-review-in-progress AI review is currently running for this PR labels Sep 4, 2026
@kubaflo
kubaflo changed the base branch from main to inflight/current September 4, 2026 21:51
@kubaflo
kubaflo merged commit 38a13be into inflight/current Sep 4, 2026
44 checks passed
@kubaflo
kubaflo deleted the jonathanpeppers-limit-uri-image-downloads branch September 4, 2026 21:51
@github-actions github-actions Bot added this to the .NET 10 SR11 milestone Sep 4, 2026
kubaflo pushed a commit that referenced this pull request Sep 6, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Limit URI image response buffering to 50 MiB so unexpectedly large
images fail to load instead of crashing the app. Allow apps to override
the limit through MSBuild or AppContext.

The new setting and its default are documented in
`docs/design/FeatureSwitches.md`.

### Issues Fixed

N/A

---------

Copilot-Session: 2933e733-3bed-4524-ae14-f7ad1c7959e6
Copilot-Session: 60d18542-ecd9-47f8-a36c-f895a934522c
kubaflo pushed a commit that referenced this pull request Sep 7, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Limit URI image response buffering to 50 MiB so unexpectedly large
images fail to load instead of crashing the app. Allow apps to override
the limit through MSBuild or AppContext.

The new setting and its default are documented in
`docs/design/FeatureSwitches.md`.

### Issues Fixed

N/A

---------

Copilot-Session: 2933e733-3bed-4524-ae14-f7ad1c7959e6
Copilot-Session: 60d18542-ecd9-47f8-a36c-f895a934522c
kubaflo pushed a commit that referenced this pull request Sep 8, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Limit URI image response buffering to 50 MiB so unexpectedly large
images fail to load instead of crashing the app. Allow apps to override
the limit through MSBuild or AppContext.

The new setting and its default are documented in
`docs/design/FeatureSwitches.md`.

### Issues Fixed

N/A

---------

Copilot-Session: 2933e733-3bed-4524-ae14-f7ad1c7959e6
Copilot-Session: 60d18542-ecd9-47f8-a36c-f895a934522c
kubaflo pushed a commit that referenced this pull request Sep 9, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Limit URI image response buffering to 50 MiB so unexpectedly large
images fail to load instead of crashing the app. Allow apps to override
the limit through MSBuild or AppContext.

The new setting and its default are documented in
`docs/design/FeatureSwitches.md`.

### Issues Fixed

N/A

---------

Copilot-Session: 2933e733-3bed-4524-ae14-f7ad1c7959e6
Copilot-Session: 60d18542-ecd9-47f8-a36c-f895a934522c
kubaflo pushed a commit that referenced this pull request Sep 11, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Limit URI image response buffering to 50 MiB so unexpectedly large
images fail to load instead of crashing the app. Allow apps to override
the limit through MSBuild or AppContext.

The new setting and its default are documented in
`docs/design/FeatureSwitches.md`.

### Issues Fixed

N/A

---------

Copilot-Session: 2933e733-3bed-4524-ae14-f7ad1c7959e6
Copilot-Session: 60d18542-ecd9-47f8-a36c-f895a934522c
kubaflo pushed a commit that referenced this pull request Sep 15, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Limit URI image response buffering to 50 MiB so unexpectedly large
images fail to load instead of crashing the app. Allow apps to override
the limit through MSBuild or AppContext.

The new setting and its default are documented in
`docs/design/FeatureSwitches.md`.

### Issues Fixed

N/A

---------

Copilot-Session: 2933e733-3bed-4524-ae14-f7ad1c7959e6
Copilot-Session: 60d18542-ecd9-47f8-a36c-f895a934522c
kubaflo pushed a commit that referenced this pull request Sep 18, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Limit URI image response buffering to 50 MiB so unexpectedly large
images fail to load instead of crashing the app. Allow apps to override
the limit through MSBuild or AppContext.

The new setting and its default are documented in
`docs/design/FeatureSwitches.md`.

### Issues Fixed

N/A

---------

Copilot-Session: 2933e733-3bed-4524-ae14-f7ad1c7959e6
Copilot-Session: 60d18542-ecd9-47f8-a36c-f895a934522c
kubaflo pushed a commit that referenced this pull request Sep 21, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Limit URI image response buffering to 50 MiB so unexpectedly large
images fail to load instead of crashing the app. Allow apps to override
the limit through MSBuild or AppContext.

The new setting and its default are documented in
`docs/design/FeatureSwitches.md`.

### Issues Fixed

N/A

---------

Copilot-Session: 2933e733-3bed-4524-ae14-f7ad1c7959e6
Copilot-Session: 60d18542-ecd9-47f8-a36c-f895a934522c
kubaflo pushed a commit that referenced this pull request Sep 27, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Limit URI image response buffering to 50 MiB so unexpectedly large
images fail to load instead of crashing the app. Allow apps to override
the limit through MSBuild or AppContext.

The new setting and its default are documented in
`docs/design/FeatureSwitches.md`.

### Issues Fixed

N/A

---------

Copilot-Session: 2933e733-3bed-4524-ae14-f7ad1c7959e6
Copilot-Session: 60d18542-ecd9-47f8-a36c-f895a934522c
kubaflo pushed a commit that referenced this pull request Sep 27, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Limit URI image response buffering to 50 MiB so unexpectedly large
images fail to load instead of crashing the app. Allow apps to override
the limit through MSBuild or AppContext.

The new setting and its default are documented in
`docs/design/FeatureSwitches.md`.

### Issues Fixed

N/A

---------

Copilot-Session: 2933e733-3bed-4524-ae14-f7ad1c7959e6
Copilot-Session: 60d18542-ecd9-47f8-a36c-f895a934522c
kubaflo pushed a commit that referenced this pull request Oct 3, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Limit URI image response buffering to 50 MiB so unexpectedly large
images fail to load instead of crashing the app. Allow apps to override
the limit through MSBuild or AppContext.

The new setting and its default are documented in
`docs/design/FeatureSwitches.md`.

### Issues Fixed

N/A

---------

Copilot-Session: 2933e733-3bed-4524-ae14-f7ad1c7959e6
Copilot-Session: 60d18542-ecd9-47f8-a36c-f895a934522c
kubaflo pushed a commit that referenced this pull request Oct 3, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Limit URI image response buffering to 50 MiB so unexpectedly large
images fail to load instead of crashing the app. Allow apps to override
the limit through MSBuild or AppContext.

The new setting and its default are documented in
`docs/design/FeatureSwitches.md`.

### Issues Fixed

N/A

---------

Copilot-Session: 2933e733-3bed-4524-ae14-f7ad1c7959e6
Copilot-Session: 60d18542-ecd9-47f8-a36c-f895a934522c
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 5, 2026
@github-actions github-actions Bot modified the milestones: .NET 10 SR11, .NET 10 SR12 Oct 21, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 02443bdc Deployed Sep 4, 2026 by jonathanpeppers via conclusion #1744
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-image Image loading, sources, caching s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-win AI found a better alternative fix than the PR s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants