You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MetadataReader throws OverflowException for a stream count >= 0x8000 #134612
The ECMA-335 metadata root's Streams field (II.24.2.1) is a 2-byte count of the stream headers that follow; CoreCLR's native metadata reader declares it USHORT iStreams. MetadataReader.ReadStreamHeaders reads it as Int16, so any value from 0x8000 up becomes negative and is passed straight to an array allocation. The result is OverflowException, where the documented failure mode is BadImageFormatException.
A count of 0x8000 or more should be treated like any other count: parsed if the stream headers are actually present, BadImageFormatException if they are not.
Actual behavior
Overflow exception is thrown.
Regression?
No
Known Workarounds
None
Configuration
.NET 10.0.7./.NET 11.0.0-rc.1.26425.128
Ubuntu x64, Windows x64
Not specific to configuration
newarr with a negative length throws OverflowException, which is what surfaces. The preceding Flags field on the line above is correctly read as UInt16; only the count is signed.
Activity
dotnet-policy-service commentedon Sep 24, 2026
Tagging subscribers to this area: @dotnet/area-system-reflection-metadata
See info in area-owners.md if you want to be subscribed.
Empiree commentedon Sep 28, 2026
Hi @pawlos, are you planning to send a PR for this? If not, I'd like to take it
pawlos commentedon Sep 28, 2026
@Empiree go ahead
Read metadata stream count as unsigned in MetadataReader (#135644)