:: commit 2c6518a5ff1e26e44cef946ec48ac28d52e4de82

Mintsuki <mintsuki@protonmail.com> — 2026-04-24 04:33

parents: 108e9590c4

lib/uri: Cap gzip stretchy-vector growth at +64 MiB per step past 64 MiB

diff --git a/common/lib/uri.c b/common/lib/uri.c
index 2850bf7e..dbc977e9 100644
--- a/common/lib/uri.c
+++ b/common/lib/uri.c
@@ -397,8 +397,11 @@ struct file_handle *uri_open(char *uri, uint32_t type, bool allow_high_mem
 
         for (;;) {
             if (buf_len == buf_cap) {
-                // Grow: new capacity = 2x (capped to prevent absurd jumps).
-                uint64_t new_cap = buf_cap * 2;
+                // Grow: double up to 64 MiB, then add 64 MiB per step.
+                // Doubling past that wastes too much memory on large files.
+                uint64_t new_cap = buf_cap < 0x4000000
+                    ? buf_cap * 2
+                    : buf_cap + 0x4000000;
                 void *new_low = NULL;
                 uint64_t new_addr = 0;
                 uri_alloc(new_cap, type, allow_high_mem, &new_low, &new_addr);
tab: 248 wrap: offon