From 94c682860d40ae87fee08f0657752125648d9a94 Mon Sep 17 00:00:00 2001 From: Songstats Audit Date: Sat, 29 Aug 2026 22:09:48 +0200 Subject: [PATCH] Fix capped container preallocation --- ext/cbor/unpacker.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/cbor/unpacker.c b/ext/cbor/unpacker.c index 9cd43e4..8e622ce 100644 --- a/ext/cbor/unpacker.c +++ b/ext/cbor/unpacker.c @@ -31,10 +31,10 @@ /* work around https://bugs.ruby-lang.org/issues/15779 for now * by limiting preallocation to about a half a Mebibyte - * limit is 2**n-1 (n==16) items so we can avoid a conditional + * limit is 2**n-1 (n==16) items */ #define SANE_PREALLOCATION_MAX 0xFFFFUL -#define SANE_PREALLOCATE(n) (n & SANE_PREALLOCATION_MAX) +#define SANE_PREALLOCATE(n) ((n) > SANE_PREALLOCATION_MAX ? SANE_PREALLOCATION_MAX : (n)) #if !defined(DISABLE_RMEM) && !defined(DISABLE_UNPACKER_STACK_RMEM) && \ MSGPACK_UNPACKER_STACK_CAPACITY * MSGPACK_UNPACKER_STACK_SIZE <= MSGPACK_RMEM_PAGE_SIZE @@ -773,4 +773,3 @@ int msgpack_unpacker_skip_nil(msgpack_unpacker_t* uk) } return 0; } -