ping: limit ICMP read buffer size

This commit is contained in:
世界 2026-06-03 10:34:17 +08:00
parent bebc8d67f3
commit 1aa83a9f92
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
3 changed files with 6 additions and 3 deletions

View file

@ -17,6 +17,9 @@ import (
"github.com/sagernet/sing/common/logger"
)
// Although its theoretical maximum may be 64k, I dont yet know of any practical use case for that. For memory-usage reasons, Im just using a 2k buffer.
const maxICMPPacketSize = 2048
var _ tun.DirectRouteDestination = (*Destination)(nil)
type Destination struct {
@ -77,7 +80,7 @@ func ConnectDestination(
func (d *Destination) loopRead() {
defer d.Close()
for {
buffer := buf.NewPacket()
buffer := buf.NewSize(maxICMPPacketSize)
err := d.conn.SetReadDeadline(time.Now().Add(d.timeout))
if err != nil {
d.logger.ErrorContext(d.ctx, E.Cause(err, "set read deadline for ICMP conn"))