fix(relaydns): cap buffer growth to prevent excessive memory allocation
Added a check to limit the buffer size to _MAX_RAW_PACKET_SIZE in the bufferGrow function to avoid potential memory exhaustion. Also refactored the size calculation into a clear newSize variable for better readability.
lemon-mint committed
Oct 28, 2025 at 12:29 UTC
4b621521b40435aab4677c8e961402c50708b51e
1 file changed
+5
-1
relaydns/helper.go
+5
-1
@@ -10,7 +10,11 @@ import (
10
11
func bufferGrow(buffer *bytebufferpool.ByteBuffer, n int) {
12
if n > cap(buffer.B) {
13
- buffer.B = make([]byte, ((n+(1<<14)-1)/1<<14)*(1<<14))
13
+ if n > _MAX_RAW_PACKET_SIZE {
14
+ n = _MAX_RAW_PACKET_SIZE
15
+ }
16
+ newSize := ((n + (1 << 14) - 1) / (1 << 14)) * (1 << 14)
17
+ buffer.B = make([]byte, newSize)
18
}
19
}
20