Skip to content
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

[release/8.0] [Blazor] Fix type name hashing when the type has multibyte characters #52316

Merged
merged 2 commits into from
Nov 27, 2023

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Nov 22, 2023

Backport of #52232 to release/8.0

/cc @MackinnonBuck

[Blazor] Fix type name hashing when the type has multibyte characters

Fixes an issue where an exception gets thrown if a render mode boundary component has a type whose full name contains multibyte characters.

Description

The bug results in an exception getting thrown if the type of a component with a render mode has a full name containing multibyte characters. It especially affects cases where a component (or the namespace it's defined in) contains non-Latin characters.

This PR fixes the issue by allocating a constant-sized stack buffer and falling back to a heap-allocated buffer when the type name is too long.

Fixes #50879
Fixes #52109

Customer Impact

Blazor Apps with non-Latin code might not be able to use interactivity. The workaround is to ensure that the full name of any component serving as a render mode boundary does not contain multibyte characters.

Regression?

  • Yes
  • No

Render modes are a new feature in .NET 8, so this bug is not a regression.

Risk

  • High
  • Medium
  • Low

The fix is straightforward and we have new automated tests for this scenario.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

@github-actions github-actions bot requested a review from a team as a code owner November 22, 2023 23:11
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Nov 22, 2023
@ghost ghost added this to the 8.0.x milestone Nov 22, 2023
@ghost
Copy link

ghost commented Nov 22, 2023

Hi @github-actions[bot]. If this is not a tell-mode PR, please make sure to follow the instructions laid out in the servicing process document.
Otherwise, please add tell-mode label.

@MackinnonBuck MackinnonBuck added the Servicing-consider Shiproom approval is required for the issue label Nov 22, 2023
@ghost
Copy link

ghost commented Nov 22, 2023

Hi @github-actions[bot]. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge.

To learn more about how to prepare a servicing PR click here.

Copy link
Member

@mkArtakMSFT mkArtakMSFT left a comment

Choose a reason for hiding this comment

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

Approved as the original PR was already reviewed and approved,

@mkArtakMSFT mkArtakMSFT added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Nov 27, 2023
@ghost
Copy link

ghost commented Nov 27, 2023

Hi @github-actions[bot]. This PR was just approved to be included in the upcoming servicing release. Somebody from the @dotnet/aspnet-build team will get it merged when the branches are open. Until then, please make sure all the CI checks pass and the PR is reviewed.

@mkArtakMSFT mkArtakMSFT merged commit 4373734 into release/8.0 Nov 27, 2023
@mkArtakMSFT mkArtakMSFT deleted the backport/pr-52232-to-release/8.0 branch November 27, 2023 21:59
@ghost ghost modified the milestones: 8.0.x, 8.0.1 Nov 27, 2023
Span<byte> typeNameHashBytes = stackalloc byte[SHA256.HashSizeInBytes];
SHA256.HashData(typeNameBytes[..written], typeNameHashBytes);

return Convert.ToHexString(typeNameHashBytes);
Copy link
Member

Choose a reason for hiding this comment

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

Between the SHA computation and the string allocation, is this something that could benefit from caching? Types cardinality is fixed, could be indexed on the type name.

Copy link
Member

Choose a reason for hiding this comment

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

This is already cached here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components Servicing-approved Shiproom has approved the issue
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants