-
Couldn't load subscription status.
- Fork 5.2k
Description
Description
We don't seem to be checking for non-overlapping buffers in the new span StringNormalizationExtensions APIs, which seems to be a correctness issue.
Reproduction Steps
using System;
public class C1
{
public static void Main()
{
char[] buffer = [.. "cafe\u0301"];
Console.WriteLine(StringNormalizationExtensions.TryNormalize(buffer, buffer, out var len));
Console.WriteLine(len);
}
}Expected behavior
Throws an error or works (if it worked, it would print 4, not 0).
Actual behavior
Prints:
True
0
Regression?
No response
Known Workarounds
Use a buffer that doesn't overlap.
Configuration
godbolt.org
https://godbolt.org/z/hv1oTWbPK
Other information
ICU documents the function we're calling into as requiring non-overlapping buffers here.
The source and destination strings must be different buffers.
But, we never check that they don't overlap.
There might be a similar concern for the Windows NLS one, I'm not certain, but it seems that the apple implementation makes copies & wouldn't need it (but it's toggleable).