Skip to content

ResourceLoader.AddLookupAssembly rollback can leave partially parsed .upri values observable #23959

Description

@autocarl

Problem

Follow-up to the post-merge review comment on PR #23707, itself following #23706.

AddLookupAssembly now removes a failed assembly registration and its parsed-resource markers when parsing throws. However, ProcessResourceFile mutates the live loader incrementally:

  1. it records the parsed marker;
  2. it obtains the live _resources dictionary;
  3. it writes each parsed pair with resources[key] = value.

If a valid .upri declares multiple entries, successfully parses and writes the first entry, then is truncated before a later key/value, BinaryReader.ReadString throws EndOfStreamException (IOException). The AddLookupAssembly catch removes the assembly from _lookupAssemblies and removes its markers, but does not restore the already-mutated live resource dictionaries.

The result can be an unregistered assembly whose partially parsed resource value remains observable.

The regression added in #23707 uses an invalid magic and therefore throws before the marker or live resource dictionary is mutated; it does not cover this partial-parse case.

Expected behavior

A failed AddLookupAssembly call should be transactional: after it throws, no registration, parsed marker, or resource value contributed by that attempt should remain observable.

Regression scenario

Emit a .upri with:

  • a valid header, loader and culture;
  • resourceCount = 2;
  • one complete key/value pair;
  • a truncated stream before the second pair.

Then assert:

  1. AddLookupAssembly throws the expected data/I/O exception;
  2. ContainsLookupAssembly(assembly) is false;
  3. the first value is not visible from the loader.

Suggested direction

Parse the assembly into temporary dictionaries and apply them only after every .upri succeeds, or rebuild live resource state from surviving registrations when registration fails.

Observed by source inspection on merged PR head 1e6b388c77ed51be12b53dc16920b8a8d9ea4249 / merge commit 2fc0049a2568a3e749fe0efb4259da64c9124c91.

Activity

  1. nickrandolph commented on Aug 4, 2026

    @nickrandolph
    Contributor

    Fix opened as #23960: AddLookupAssembly now parses a newly registered assembly's .upri files into temporary dictionaries and merges them into the live loaders only after every file parsed successfully (mirroring RebuildLoaderResourcesFromSurvivors), and the full-reload failure path re-derives the merged state from the surviving registrations. Includes red/green regression tests for the truncated-.upri scenario covering both parse branches.

  2. added a commit that references this issue on Sep 3, 2026
    e47e138
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions