From daf67dc1e66dc3e67dd451637163a22aee9bcc2d Mon Sep 17 00:00:00 2001 From: TwiN Date: Mon, 11 Aug 2025 09:36:55 -0400 Subject: [PATCH] perf: Cap RANDOM_STRING_N to 8182 (#1193) --- README.md | 2 +- config/endpoint/endpoint.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 534e378d..6562c79e 100644 --- a/README.md +++ b/README.md @@ -295,7 +295,7 @@ You may use the following placeholders in the body (`endpoints[].body`): - `[ENDPOINT_GROUP]` (resolved from `endpoints[].group`) - `[ENDPOINT_URL]` (resolved from `endpoints[].url`) - `[LOCAL_ADDRESS]` (resolves to the local IP and port like `192.0.2.1:25` or `[2001:db8::1]:80`) -- `[RANDOM_STRING_N]` (resolves to a random string of numbers and letters of length N) +- `[RANDOM_STRING_N]` (resolves to a random string of numbers and letters of length N (max: 8192)) ### External Endpoints diff --git a/config/endpoint/endpoint.go b/config/endpoint/endpoint.go index 5153a45b..d425bfa1 100644 --- a/config/endpoint/endpoint.go +++ b/config/endpoint/endpoint.go @@ -344,6 +344,9 @@ func (e *Endpoint) getParsedBody() string { if err == nil { body = randRegex.ReplaceAllStringFunc(body, func(match string) string { n, _ := strconv.Atoi(match[15 : len(match)-1]) + if n > 8192 { + n = 8192 // Limit the length of the random string to 8192 bytes to avoid excessive memory usage + } const availableCharacterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" b := make([]byte, n) for i := range b {