Repository navigation
Fix deleted field filtering through FieldPtr in MDInternalRW::EnumInit - #137787
Closed
davidwrighton wants to merge 1 commit into
Closed
davidwrighton wants to merge 1 commit into
davidwrighton wants to merge 1 commit into
Conversation
When metadata has HAS_DELETE set and uses a FieldPtr indirection table, MDInternalRW::EnumInit(mdtFieldDef) checked the deleted state of the Field row at the FieldPtr index instead of the Field row the FieldPtr entry points to. With a reordered FieldPtr table this could hide live fields and expose deleted ones. Use the translated RID, matching the MethodDef path. Add a regression test that loads hand-crafted uncompressed (#-) metadata with a reordered FieldPtr table and a deleted global field. Co-authored-by: Copilot <[email protected]>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @agocke |
Member
Author
|
Eh, some more investigation indicates that deleted fields are even less supported than I thought. Instead of fixing them, I'm going to open a PR to simply delete the deletion support from the metadata implementation. |
davidwrighton
added a commit
that referenced
this pull request
Nov 21, 2026
CoreCLR's metadata engine had a legacy "deleted token" convention: incremental emitters set `HAS_DELETE` (0x80), `IMetaDataEmit::DeleteToken` renamed records to `_Deleted*` or cleared their parent, and importers filtered those records out. The runtime has no callers of `DeleteToken` and does not open scopes in `MDUpdateIncremental` mode. Modern EnC does not require the deleted-name convention; see #118903. The filtering also contained a `FieldPtr` indexing bug addressed separately by #137787. This PR removes the obsolete deletion machinery rather than retaining that special case. ## Changes - Remove deleted-record filtering from the internal and public metadata enumerators and from global-method merging. - Make public `IMetaDataEmit::DeleteToken` return `E_NOTIMPL`, preserving its vtable slot. - Stop setting `HAS_DELETE` in incremental update mode and remove the associated update-mode rejection and `metainfo` retry. - Treat `HAS_DELETE` as a reserved, ignored bit. Existing incremental-mode images remain loadable even if they carry this bit. - Reject `DELTA_ONLY` (0x20) outside the internal delta-application path, for both compressed (`#~`) and uncompressed (`#-`) metadata. A normal image with `HAS_DELETE | DELTA_ONLY` (0xA0) is rejected because of `DELTA_ONLY`, not because of `HAS_DELETE`. - Remove `COR_DELETED_NAME_*` and `IsDeletedName` from the native headers. These headers are not maintained as stable, backward-compatible public headers. - Add `DeletedMetadataFlags`, covering successful loads with and without `HAS_DELETE` and rejection with `DELTA_ONLY`, in both metadata formats. - Make public `IMetaDataEmit::ApplyEditAndContinue` return `E_NOTIMPL`, preserving its vtable slot. There are no in-repository callers of this public API. - Restore the `MetaDataImportOption` GUID and `CorImportOptions` declarations with their original values, including `MDImportOptionAll = 0xFFFFFFFF`. `IMetaDataDispenserEx::SetOption` accepts the option as a validated `VT_UI4` no-op, allowing existing callers to request `MDImportOptionAll` before opening ordinary metadata. - Extend the existing metadata-dispenser profiler test to exercise both behaviors. ## Behavior Change Deleted-record names and markers no longer hide metadata records, and `DeleteToken` returns `E_NOTIMPL`. `HAS_DELETE` alone does not prevent an image from loading. Ordinary loads reject `DELTA_ONLY`. The public `IMetaDataEmit::ApplyEditAndContinue` API is retired. This is separate from the internal `IMDInternalImport::ApplyEditAndContinue` API used by debugger EnC and `MetadataUpdater.ApplyUpdate`. Both internal delta readers pass `fIsDelta = true`, so those paths continue accepting EnC deltas, including the 0xA0 flags emitted by System.Reflection.Metadata. ## Validation Validated locally on linux-x64 with a Checked runtime: - `./build.sh clr.native+clr.iltools -c checked` - passed. - `./build.sh clr.corelib+clr.nativecorelib+libs.pretest -rc checked` - passed; refreshed stale baseline CoreLib artifacts. - `src/tests/build.sh -Test profiler/unittest/metadatagetdispenser.csproj x64 checked` - passed. - `src/tests/build.sh -GenerateLayoutOnly x64 checked` - passed. - The metadata-dispenser profiler test, run with `corerun` from its output directory, failed against the pre-change runtime (`ApplyEditAndContinue` returned `E_NOINTERFACE` instead of `E_NOTIMPL`) and passed against the updated runtime, including setting `MDImportOptionDefault` and `MDImportOptionAll` before opening scopes. - `src/tests/build.sh -Test reflection/DeletedMetadata/DeletedMetadataFlags.csproj x64 checked` - passed; the generated test executable passed with exit code 100. - `./build.sh libs.pretest -c Release -rc checked` - passed. - `./dotnet.sh build src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj -c Release /t:Test /p:RuntimeConfiguration=Checked '/p:XUnitOptions=-class System.Reflection.Metadata.ApplyUpdateTest'` - passed all 24 tests, with no failures or skips. Supersedes #137787. > [!NOTE] > This PR description and the code changes were generated with GitHub Copilot. --------- Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MDInternalRW::EnumInit(mdtFieldDef)handles metadata that hasHAS_DELETEset. In that path it translates each FieldPtr index to a field RID, but then checks the deleted flag onGetFieldRecord(index, ...)instead ofGetFieldRecord(fieldRid, ...). When the FieldPtr table reorders fields, it checks the wrong field's deleted state. As a result, deleted fields can appear in enumeration (and in reflection/type loading) while live fields are skipped. The MethodDef path in the same function, and the public importer (import.cpp), already use the translated RID.Repro / regression test
src/tests/reflection/DeletedMetadata/DeletedFieldEnumerationbuilds a small library with hand-written uncompressed (#-) metadata. CoreCLR opens this format with the RW importer. The metadata has:HAS_DELETEheap bit setLive, and a deleted_Deletedfield (SpecialName | RTSpecialName)FieldPtrtable that reverses the physical field orderIt loads the library with
Assembly.Load(byte[])and checksManifestModule.GetFields().["_Deleted"]instead of["Live"]. A control image with identity FieldPtr ordering returns["Live"].["Live"].Validation (linux-x64 Checked)
src/tests/build.sh -Test reflection/reflection.csproj x64 Checked: succeeded.corerun reflection.dllon the existing, unfixed runtime:DeletedFieldEnumerationfailed (Expected: ["Live"],Actual: ["_Deleted"])../build.sh clr.runtime -c checkedplus./build.sh clr.corelib -c checked, with the outputs copied into Core_Root, thencorerun reflection.dll: all 15 tests passed, includingDeletedFieldEnumeration.Note
This PR description and change were generated with GitHub Copilot.