From 79cdd2b252a18b3be102d357bb12f913c057ef2e Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 14 Dec 2024 00:40:14 +0800 Subject: [PATCH] ... --- src/common/vector.c | 3 ++- tests/98_lz4.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/vector.c b/src/common/vector.c index 87d9370f..5b91f11d 100644 --- a/src/common/vector.c +++ b/src/common/vector.c @@ -30,7 +30,8 @@ c11_vector c11_vector__copy(const c11_vector* self){ void c11_vector__reserve(c11_vector* self, int capacity){ if(capacity < 4) capacity = 4; if(capacity <= self->capacity) return; - self->data = realloc(self->data, self->elem_size * capacity); + // self->elem_size * capacity may overflow + self->data = realloc(self->data, self->elem_size * (size_t)capacity); self->capacity = capacity; } diff --git a/tests/98_lz4.py b/tests/98_lz4.py index 9bcb6707..5cdb2a6e 100644 --- a/tests/98_lz4.py +++ b/tests/98_lz4.py @@ -25,3 +25,7 @@ def gen_data(): for i in range(100): ratio = test(gen_data()) # print(f'compression ratio: {ratio:.2f}') + +# test 100MB of random data +rnd = [random.randint(0, 255) for _ in range(1024*1024*100)] +test(bytes(rnd))