Within HostnameError.Error(), when constructing an error string, there is no limit to the number of hosts that will be printed out.
Furthermore, the error string is constructed by repeated string concatenation, leading to quadratic runtime.
Therefore, a certificate provided by a malicious actor can result in excessive resource consumption.
HostnameError.Error() now limits the number of hosts and utilizes strings.Builder when constructing an error string.
Thanks to Philippe Antoine (Catena cyber) for reporting this issue.
This is CVE-2025-61729 and Go issue #76445 (this one).
This is a PRIVATE issue for CVE-2025-61729, tracked in http://b/450936127 and fixed by https://go-internal-review.git.corp.google.com/c/go/+/3000.
/cc @golang/security and @golang/release