Repository navigation
fix(resources): make AddLookupAssembly transactional on parse failure - #23960
Conversation
|
Nick Randolph seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a correctness bug in Windows.ApplicationModel.Resources.ResourceLoader.AddLookupAssembly where a malformed/truncated .upri could partially merge values into live loader dictionaries before throwing, leaving those values observable even after the lookup-assembly registration rollback. The change makes AddLookupAssembly transactional across both code paths so that failed registrations leave no observable resource values or parsed markers behind.
Changes:
- Make the “single-assembly” parse path transactional by parsing
.upricontent into temporary dictionaries/marker sets and applying only after all files parse successfully. - Strengthen rollback for the “full-reload” path by rebuilding merged loader state from surviving registrations after a parse failure.
- Add regression tests that embed a truncated-but-valid
.upripayload and assert no partial values leak across bothAddLookupAssemblybranches.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Uno.UWP/ApplicationModel/Resources/ResourceLoader.static.cs | Adds transactional assembly parsing and robust rollback via rebuild-from-survivors when reload-path parsing fails. |
| src/Uno.UI.UnitTests/ResourceLoader/Given_ResourceLoader_Alc.cs | Adds red/green coverage for truncated .upri partial-merge leaks and introduces a reusable helper to emit assemblies embedding arbitrary .upri payloads. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23960/wasm-skia-net9/index.html |
carldebilly
left a comment
There was a problem hiding this comment.
Review of 8fbeb65 (head unchanged since analysis). The core fix holds up under inspection: both AddLookupAssembly branches are now genuinely transactional, the removed RemoveWhere rollback is indeed dead in both branches, the temp-marker seeding preserves skip semantics (markers are per-(assembly, fileName)), the temp/live dictionary comparers match, and the two regression tests deterministically pin the two distinct branches (PrimaryLanguageOverride's setter never re-enters the loader). No public API change; a hostile .upri cannot pre-size any allocation from its declared resourceCount, and the PE-emission helper is test-scoped — nice exotic-code hygiene overall.
Findings below: 1 high (diagnosability of the rollback path), 6 medium (recovery robustness + PreserveParsedResources semantics, a third copy of the temp-then-apply pattern, a contradictory/overclaiming comment block, test metadata, exception contract, test-seam fidelity), 2 low. Two notes not anchored inline: several of the new comment blocks run 4–6 lines where repo guidance is one or two — worth a trim; and setting liveLoadersTouched = true just before the apply loop in ProcessAssemblyTransactionally would extend the recovery to a (pathological) mid-apply failure for free.
Overall: fix-first — the logging gap and the unguarded recovery call are cheap to address and materially change how a production failure gets investigated.
|
@carldebilly — thanks for the review, this was a genuinely useful one. All 10 threads addressed and resolved in Your Verification (base =
Two things are your call, and I deliberately did not decide them unilaterally:
One process note in the interest of honesty about provenance: the AST index I normally use for impact analysis isn't configured for this repo in my environment, so the "single caller of |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/Uno.UWP/ApplicationModel/Resources/ResourceLoader.static.cs:540
resourceCountis read before thetrythat convertsEndOfStreamExceptionintoInvalidDataException, so a stream truncated right before/inside the count read will still surface asEndOfStreamExceptioninstead of the documentedInvalidDataExceptionthat names the file. Move theReadInt32()into thetryso all truncation points in the entry list are normalized consistently.
var resourceCount = reader.ReadInt32();
StringBuilder sb = new();
try
{
for (var i = 0; i < resourceCount; i++)
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23960/wasm-skia-net9/index.html |
|
Follow-up: acting on the suppressed Copilot comment from the review of
Red/green, run both ways:
Two notes on scope, since I checked before deciding how far to take this:
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23960/wasm-skia-net9/index.html |
autocarl
left a comment
There was a problem hiding this comment.
Follow-up review — fix-first
The refactor makes AddLookupAssembly and ReloadResources transactional, but the survivor-rebuild path can still commit partial state from an assembly that its catch block says it skipped.
Validated locally on the exact head 99a89d5aec225f128414de33b339420cb2033cd2:
- the existing bad-magic survivor test passes (1/1), because it fails before mutating the temporary parse state;
- a disposable regression using a valid header,
resourceCount = 2, one complete pair, then truncation before the second pair fails (1/1); - after
ClearAlcAssemblies,TryGetMergedResourceForTestsstill findsTruncatedKey = TruncatedValue.
Technical verdict: HIGH / fix-first. I am submitting a COMMENT review rather than CHANGES_REQUESTED because this account has read-only repository permission; the maintainers retain the formal Go/No-Go decision.
There was a problem hiding this comment.
🟢 Approval recommended
The transactional refactor is localized, maintains existing semantics, and is backed by targeted regression tests for the previously leaking truncation scenario.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23960/wasm-skia-net9/index.html |
|
CI is green on One check went red mid-run and is worth explaining, in case anyone saw it:
The log shows the last test started was For the record, that leg cannot reach this change: @carldebilly — green and ready whenever you have a moment. |
- parse a newly registered assembly's .upri files into temporary dictionaries and merge into the live loaders only after every file parsed successfully (same temp-then-apply pattern as RebuildLoaderResourcesFromSurvivors) - when the failing registration went through the full reload path, re-derive the merged values and parsed markers from the surviving registrations so a truncated .upri's partially parsed pairs cannot remain observable after the rollback - drop the now-dead live marker rollback (a failing parse no longer writes markers into the live set) - add red/green regression tests covering both AddLookupAssembly parse branches with a .upri that declares two pairs and truncates after the first Fixes #23959 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…actional parse Review follow-up on the transactional `AddLookupAssembly` fix. - Extract `TransactionalParse` (temp dictionaries + marker set + resolver + merge/replace apply) and route `AddLookupAssembly`, `ReloadResources` and `RebuildLoaderResourcesFromSurvivors` through it, replacing three hand-rolled copies of the temp-then-apply pattern. - `ReloadResources` is now transactional too, so the culture-change path via `EnsureLoadersCultures` no longer leaks partial state; the `liveLoadersTouched` control flag and the rebuild-on-failure recovery in the catch are both gone. - Log the rollback before rethrowing (gated on `LogLevel.Error`), naming the assembly and whether the whole cache was being reloaded. - Restate a `.upri` truncated mid key/value pair as `InvalidDataException` naming the file, matching every other malformed-`.upri` case, instead of surfacing `BinaryReader`'s context-free `EndOfStreamException`. - Hand the parsed dictionary over on a `TryGetValue` miss instead of allocating an empty one and copying every pair. - Document the language-preference narrowing `RebuildLoaderResourcesFromSurvivors` applies when `PreserveParsedResources` is enabled. - Tests: add `[Description]` + `[GitHubWorkItem]`, assert the documented exception type, assert the truncated loader instance is never created, and replace the private-field reflection helper with the `TryGetMergedResourceForTests` / `ContainsNamedLoader` internal seams. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Move the resource-count read inside the try that restates EndOfStreamException as the documented InvalidDataException, so a stream ending at the count is named like every other truncation point instead of leaking BinaryReader's context-free exception. - Keep the declared count in the message when it was read, and say so explicitly when the truncation preceded it. - Add a red/green regression test for a .upri truncated before its count (fails with EndOfStreamException on the previous code). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- give each survivor in RebuildLoaderResourcesFromSurvivors its own scratch TransactionalParse, folded into the aggregate only once its Parse returned - the shared parse let a survivor add a marker and its first key/value pair before throwing on a later pair; the guard caught, the loop continued, and the apply phase published the rejected survivor's partial state - roll values AND markers back together: a leaked marker makes a later parse skip a file it should have read - factor the temp-to-live merge loop into MergeInto so the new temp-to-temp fold reuses the same last-writer-wins-per-key semantics - add the truncated-after-first-pair rebuild regression, plus the counterpart assertion that a good survivor's values are still published Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
3c55309 to
09ad807
Compare
|
Retargeted to This also explains the conflict, and corrects something I said earlier. The PR reported
The 12 are And the red proof now runs on the branch that will actually ship it. Reverting only so every one of the four commits is load-bearing here, not just on the branch it was written against. Restoring the file returns 10/10. CI is running on the new base; nothing has failed yet (the rollup briefly read FAILURE while every context was still queued or in progress). Reviewers unchanged: @carldebilly, autocarl, copilot. |
There was a problem hiding this comment.
🟢 Approval recommended
The transactional parsing change is consistent across all mutation paths described, and the added tests directly cover the previously leaking partial-parse scenarios.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
@mergify backport master |
✅ Backports have been createdDetails
Cherry-pick of a44268e has failed: Cherry-pick of 4488087 has failed: Cherry-pick of 09ad807 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
The backport recreated ResourceLoader.static.cs under the removed Uno.UWP folder and deleted the live Uno.WinRT copy; move it back. Port the transactional-parse changes onto master's Uno.WinRT file, keeping its UPRI v3 parser, and reject an unreadable stream or an out-of-range name length as InvalidDataException. Co-Authored-By: Claude Opus 5.5 <[email protected]>
GitHub Issue: closes #23959
PR Type:
🐞 Bugfix
What changed? 🚀
Follow-up to #23707.
AddLookupAssemblyrolled back the_lookupAssembliesregistration and parsed-resource markers when parsing threw, butProcessResourceFilemerges each key/value pair straight into the live loader dictionaries as it reads. A.upriwith a valid header that declares two pairs, carries one complete pair, then truncates fails on the second pair — after the rollback, the unregistered assembly's first pair remained observable throughGetString(permanently, when the loader context was already established, since no later lookup reloads).Every path that mutates the live loader state now goes through a single transactional parse.
TransactionalParse(new private nested type) owns the temp dictionaries, the temp marker set, the loader resolver, and the two apply phases (MergeIntoLiveLoaders,ReplaceLiveLoaders). It replaces the three hand-rolled copies of the temp-then-apply pattern the file had grown.AddLookupAssembly— single-assembly branch (changed loader context):ProcessAssemblyTransactionallyparses into temporaries with the marker set seeded from the assembly's already-parsed markers, so skip semantics are unchanged, and merges only after every file parsed successfully.AddLookupAssembly— full-reload branch:ReloadResourcesis itself transactional now, so the failure never touches the live state. That also makes the culture-change path (EnsureLoadersCultures→ReloadResources) transactional, which the earlier revision did not cover.liveLoadersTouchedcontrol flag, theRebuildLoaderResourcesFromSurvivors()recovery call in the catch, and the live-marker rollback (_parsedResources.RemoveWhere) are all gone: removing the list entry is the whole rollback.RebuildLoaderResourcesFromSurvivorskeeps its per-assembly guard and is still used by the ALC sweep.ClearResources()and the two-argumentProcessAssemblyoverload became unused and were removed._log.IsEnabled(LogLevel.Error)), reporting the assembly whose registration was rolled back and whether the whole cache was being reloaded — in that branch the faulting.uprican belong to a pre-existing registration rather than to the assembly being rolled back..upritruncated in the middle of its declared pairs surfacedBinaryReader's context-freeEndOfStreamException.ProcessResourceFilenow restates it asInvalidDataException($"Truncated resource file {fileName}: …", error), matching what it already does (and documents) for every other malformed-.upricase.InvalidDataExceptionis already in the rebuild guard's filter, so recovery semantics are unchanged.TryGetValuemiss instead of allocating an empty dictionary and copying every pair — the zero-copy ownership transferRebuildLoaderResourcesFromSurvivorsalready used.RebuildLoaderResourcesFromSurvivorsre-derives values only for the last established context's language preferences, so withPreserveParsedResourcesenabled it drops values preserved for other cultures (they are re-parsed the next time those languages become active). That is now stated in its XML docs.The
HasContextChangedSignificantlybranch selection inAddLookupAssemblyis unchanged; the two comments describing those branches were swapped and are now accurate.Red/green regression tests
Two new tests in
Given_ResourceLoader_Alcemit (in memory, viaManagedPEBuilder) an assembly embedding a.upriwith valid magic/version/name/culture,resourceCount = 2, one complete pair, truncated before the second pair. Both carry[Description]and[GitHubWorkItem]:When_AddLookupAssembly_Truncated_Upri_Then_Throws_And_Partial_Value_Not_Observable— established loader context (full-reload branch): assertsAddLookupAssemblythrowsInvalidDataException,ContainsLookupAssemblyis false, the truncated.upri's loader instance was never created, the first pair's value is not returned byGetString, and surviving registrations still resolve.When_AddLookupAssembly_Truncated_Upri_With_Changed_Context_Then_Live_Loaders_Untouched— changed loader context (single-assembly branch): asserts the throw, the rollback, that the loader instance was never created (absence, not emptiness, so a regression to the full-reload branch cannot keep the test green), and that no value reached the live loaders.Live state is observed through two new
internaltest seams next toContainsLookupAssembly—TryGetMergedResourceForTestsandContainsNamedLoader— replacing the private-field reflection helper the earlier revision used.GetStringcannot be used for these assertions: it re-establishes the loader context and would reload (and wipe) the loaders, masking the leak.Both tests fail on the pre-fix code with the leaked
TruncatedValueobservable in both branches, and on the loader-instance assertions, and pass with the fix. FullGiven_ResourceLoader_Alc(8 tests) andGiven_AlcCacheSweep(4 tests) pass; the fullUno.UI.UnitTestsrun is 4074 total / 12 failed, and those 12When_Gregorian_FixedDate*failures reproduce identically on the unmodified merge commit2fc0049a256(4072 total / same 12) — environment-dependent, unrelated.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code