Skip to content

IPAddress.TryParse(ROS<byte>) accepts invalid UTF-8 #111288

@MihaZupan

Description

@MihaZupan

For example:

IPAddress.Parse([.. "::A%"u8, 255]); // Does not throw

Now that IPAddress accepts parsing bytes (new in .NET 10 - #102144), we seem to also be accepting invalid UTF-8 here:

case '%':
// An IPv6 address is separated from its scope by a '%' character. The scope
// is terminated by the natural end of the address, the address end character (']')
// or the start of the prefix ('/').
while (i + 1 < end)
{
i++;
if (name[i] == TChar.CreateTruncating(']'))
{
goto case ']';
}
else if (name[i] == TChar.CreateTruncating('/'))
{
goto case '/';
}
}
break;

Not sure this is a real issue, but given that the parameters are explicitly named as utf8 (bool TryParse(ReadOnlySpan<byte> utf8Text, ...)) the user may be expecting that a parsed value is also valid UTF-8.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions