From 07e9138c87f6297739484ab703fafa475871f736 Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Fri, 30 Oct 2026 03:40:56 +0000 Subject: [PATCH] upstream: grow destination buffer more aggressively to avoid bad worst-case behaviour when lots of characters that need escaping are processed Anthropic ANT-2026-P8BKU1E3 OpenBSD-Commit-ID: 864b76c7cd9c91c9a2b692e93d99b1ce0b0d32c3 --- utf8.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/utf8.c b/utf8.c index c2cd02b67..e30d78fb6 100644 --- a/utf8.c +++ b/utf8.c @@ -1,4 +1,4 @@ -/* $OpenBSD: utf8.c,v 1.11 2020/05/01 06:28:52 djm Exp $ */ +/* $OpenBSD: utf8.c,v 1.12 2026/10/30 03:40:56 djm Exp $ */ /* * Copyright (c) 2016 Ingo Schwarze * @@ -77,7 +77,12 @@ grow_dst(char **dst, size_t *sz, size_t maxsz, char **dp, size_t need) if (*dp + need < *dst + *sz) return 0; - tsz = *sz + 128; + /* + * Grow geometrically to avoid recallocarray repeatedly having to + * copy its buffer as the allocation grows. + * Note: maxsz is always <=INT_MAX so we can't overflow the size_t; + */ + tsz = *sz + (*sz > 128 ? *sz : 128); if (tsz > maxsz) tsz = maxsz; if ((tp = recallocarray(*dst, *sz, tsz, 1)) == NULL)