Skip to content

Conversation

adamsitnik
Copy link
Member

The fuzzer has discovered something that I was not aware of when authoring the fuzz tests.

When AssemblyNameInfo.ToAssemblyName sets the AssemblyName.CultureInfo:

A CultureInfo is being allocated:

public string? CultureName
{
get => _cultureInfo?.Name;
set => _cultureInfo = (value == null) ? null : new CultureInfo(value);

Which calls CultureData.GetCultureData with the provided name and consumes the returned result:

_cultureData = CultureData.GetCultureData(name, useUserOverride) ??
throw new CultureNotFoundException(nameof(name), name, GetCultureNotSupportedExceptionMessage());
_name = _cultureData.CultureName;

Which internally performs ToLower on the provided name, just to be able to cache it:

string hashName = AnsiToLower(useUserOverride ? cultureName : cultureName + '*');

and later normalizes the name also by lowering it:

if (char.IsAsciiLetterUpper(name[i]))
{
// lowercase characters before '-'
normalizedName[i] = (char)(((int)name[i]) + 0x20);
changed = true;
}

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adjusts tests to account for the culture name normalization behavior when converting AssemblyNameInfo to AssemblyName.

  • Added a new test in AssemblyNameInfoTests.cs to verify that the CultureInfo constructor lower-cases the culture name.
  • Updated the fuzzer in AssemblyNameInfoFuzzer.cs to conditionally verify the lower-cased culture name.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Reflection.Metadata/tests/Metadata/AssemblyNameInfoTests.cs Added a test validating the normalization of the culture name when converting to AssemblyName.
src/libraries/Fuzzing/DotnetFuzzing/Fuzzers/AssemblyNameInfoFuzzer.cs Modified assertions to verify culture name normalization based on whether the culture name is null or not.

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.

@jkotas jkotas merged commit a2e1d21 into dotnet:main Apr 5, 2025
85 of 87 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants