Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MetadataAggregator.GetGenerationHandle returns incorrect results for Guid heap handles #113910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tmat opened this issue Mar 26, 2025 · 7 comments · May be fixed by #115268
Open

MetadataAggregator.GetGenerationHandle returns incorrect results for Guid heap handles #113910

tmat opened this issue Mar 26, 2025 · 7 comments · May be fixed by #115268
Labels
area-System.Reflection.Metadata bug good first issue Issue should be easy to implement, good for first-time contributors help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@tmat
Copy link
Member

tmat commented Mar 26, 2025

Description

guidSizes is incorrectly accumulated here:

https://github.com/dotnet/runtime/blob/main/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/MetadataAggregator.cs#L156

The size of GUID heap in aggregated metadata is the same as the size in the metadata delta where the GUID is used (unlike other heaps).

Regression?

No

Known Workarounds

See dotnet/metadata-tools#308

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Mar 26, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-reflection-metadata
See info in area-owners.md if you want to be subscribed.

@tmat tmat assigned tmat and unassigned tmat Mar 26, 2025
@tmat tmat added good first issue Issue should be easy to implement, good for first-time contributors help wanted [up-for-grabs] Good issue for external contributors labels Mar 26, 2025
@ericstj ericstj added bug and removed untriaged New issue has not been triaged by the area owner labels Mar 31, 2025
@ericstj ericstj added this to the 10.0.0 milestone Mar 31, 2025
@ericstj
Copy link
Member

ericstj commented Mar 31, 2025

@tmat I see you have added a workaround. Are you aware of any downstream callers of this API (like Roslyn) who might be impacted by this?

Did you want to suggest a fix?

@tmat
Copy link
Member Author

tmat commented Mar 31, 2025

I see you have added a workaround. Are you aware of any downstream callers of this API (like Roslyn) who might be impacted by this?

I'm not aware of any. Not high priority to fix. Would be nice to remove the workaround.

Did you want to suggest a fix?

The line referenced above needs to be updated to no accumulate. Then some comments and tests need to be updated.
Should be easy to do.

@fabrimaz
Copy link

fabrimaz commented May 1, 2025

Hello, I am trying to read this thread and hope to understand it so that I could start contributing this as my first task.
I guess I will need a bit of guidance, though.
I am not sure if I got what the recently added workaround should be replaced with.

@fabrimaz
Copy link

fabrimaz commented May 1, 2025

Can you elaborate on The line referenced above needs to be updated to no accumulate.?
Do you mean something like guidSizes[r + 1] = deltaReaders[r].GetHeapSize(HeapIndex.Guid) / guidSize;?

@tmat
Copy link
Member Author

tmat commented May 1, 2025

When #Guid heap is emitted in delta metadata the compiler first writes N empty guids in the heap. where N is number of Guids in all previous generations including the baseline DLL, and then writes guids used in the delta.

Like so:

Baseline DLL: {Guid 1} ... {Guid N0}
Generation 1 delta: {empty guid} ... {empty guid} {Guid N0+1} ... {Guid N0 + N1}
Generation 2 delta: {empty guid} ... {empty guid} {empty guid} ... {empty guid} {Guid N0+N1+1} ... {Guid N0 + N1 + N2}

This is therefore not correct:

guidSizes[r + 1] = guidSizes[r] + deltaReaders[r].GetHeapSize(HeapIndex.Guid) / guidSize;

guidSizes[r] shouldn't be added to guidSizes[r+1].

Instead the size of Guid heap in generation r is simply: deltaReaders[r].GetHeapSize(HeapIndex.Guid) / guidSize;

@fabrimaz
Copy link

fabrimaz commented May 3, 2025

I just opened this:
#115268
Let me know if it could be fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Reflection.Metadata bug good first issue Issue should be easy to implement, good for first-time contributors help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants