Skip to content

Fix seed initialization in Microsoft.Bcl.Hashcode #42808

@fabricefou

Description

@fabricefou

Description

Private field s_seed is always set to 0 due to a bug in method GetRandomBytes.
In this method the parameter byte* buffer is always overwritten, so random value is lost.

We can easily reproduce the problem with this code.

var seed = typeof(HashCode).GetField("s_seed", BindingFlags.NonPublic | BindingFlags.Statics);

This problem don't existe in .NET Core implementation.

Configuration

.NET Framework

Regression?

It's not really a regression but not the expected behavior.
People using this package want the same behavior than in .NET core.

And if it's not fixed, I think this package should be mark as deprecated.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions