From 8ba8702cbf86e0235d0c349997210276997dc854 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Sat, 11 Apr 2026 18:40:10 +0200 Subject: [PATCH] Don't pre-allocate strings larger than the buffered size --- ext/msgpack/unpacker.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/msgpack/unpacker.c b/ext/msgpack/unpacker.c index ca8d0640..ad4d6630 100644 --- a/ext/msgpack/unpacker.c +++ b/ext/msgpack/unpacker.c @@ -336,7 +336,8 @@ static int read_raw_body_cont(msgpack_unpacker_t* uk) size_t length = uk->reading_raw_remaining; if(uk->reading_raw == Qnil) { - uk->reading_raw = rb_str_buf_new(length); + size_t buffered_size = msgpack_buffer_all_readable_size(UNPACKER_BUFFER_(uk)); + uk->reading_raw = rb_str_buf_new(length > buffered_size ? buffered_size : length); } do {