mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-27 18:30:54 +08:00
strings.ReplaceAll, bytes.ReplaceAll and regexp.ReplaceAllString built their result and only then charged its length against the memory budget. A hook that replaces each byte of a 1 MiB string with another 1 MiB string makes the runtime ask for 1 TiB, and the server exits with "fatal error: runtime: out of memory" before the limit is checked. The length of the result is now computed from the match count and charged first. For a regexp template, each match is bounded by the template with every $ reference expanded to the whole match.