From 7595745e2956bf2a980ee6bc7ffcdd04510d7534 Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Sun, 22 Oct 2023 13:37:21 -0400 Subject: [PATCH 1/2] Add length checks to puppets Signed-off-by: Clayton Smith --- .../volk_32f_8u_polarbutterflypuppet_32f.h | 12 +++++++++++ .../volk/volk_8u_x3_encodepolarpuppet_8u.h | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/kernels/volk/volk_32f_8u_polarbutterflypuppet_32f.h b/kernels/volk/volk_32f_8u_polarbutterflypuppet_32f.h index e3dec3ec9..6962a26cf 100644 --- a/kernels/volk/volk_32f_8u_polarbutterflypuppet_32f.h +++ b/kernels/volk/volk_32f_8u_polarbutterflypuppet_32f.h @@ -81,6 +81,10 @@ static inline void volk_32f_8u_polarbutterflypuppet_32f_generic(float* llrs, unsigned char* u, const int elements) { + if (elements < 2) { + return; + } + unsigned int frame_size = maximum_frame_size(elements); unsigned int frame_exp = log2_of_power_of_2(frame_size); @@ -104,6 +108,10 @@ static inline void volk_32f_8u_polarbutterflypuppet_32f_u_avx(float* llrs, unsigned char* u, const int elements) { + if (elements < 2) { + return; + } + unsigned int frame_size = maximum_frame_size(elements); unsigned int frame_exp = log2_of_power_of_2(frame_size); @@ -127,6 +135,10 @@ static inline void volk_32f_8u_polarbutterflypuppet_32f_u_avx2(float* llrs, unsigned char* u, const int elements) { + if (elements < 2) { + return; + } + unsigned int frame_size = maximum_frame_size(elements); unsigned int frame_exp = log2_of_power_of_2(frame_size); diff --git a/kernels/volk/volk_8u_x3_encodepolarpuppet_8u.h b/kernels/volk/volk_8u_x3_encodepolarpuppet_8u.h index ec6c955ab..496ca2e58 100644 --- a/kernels/volk/volk_8u_x3_encodepolarpuppet_8u.h +++ b/kernels/volk/volk_8u_x3_encodepolarpuppet_8u.h @@ -48,6 +48,10 @@ volk_8u_x3_encodepolarpuppet_8u_generic(unsigned char* frame, const unsigned char* info_bits, unsigned int frame_size) { + if (frame_size < 1) { + return; + } + frame_size = next_lower_power_of_two(frame_size); unsigned char* temp = (unsigned char*)volk_malloc(sizeof(unsigned char) * frame_size, volk_get_alignment()); @@ -67,6 +71,10 @@ volk_8u_x3_encodepolarpuppet_8u_u_ssse3(unsigned char* frame, const unsigned char* info_bits, unsigned int frame_size) { + if (frame_size < 1) { + return; + } + frame_size = next_lower_power_of_two(frame_size); unsigned char* temp = (unsigned char*)volk_malloc(sizeof(unsigned char) * frame_size, volk_get_alignment()); @@ -85,6 +93,10 @@ volk_8u_x3_encodepolarpuppet_8u_u_avx2(unsigned char* frame, const unsigned char* info_bits, unsigned int frame_size) { + if (frame_size < 1) { + return; + } + frame_size = next_lower_power_of_two(frame_size); unsigned char* temp = (unsigned char*)volk_malloc(sizeof(unsigned char) * frame_size, volk_get_alignment()); @@ -108,6 +120,10 @@ volk_8u_x3_encodepolarpuppet_8u_a_ssse3(unsigned char* frame, const unsigned char* info_bits, unsigned int frame_size) { + if (frame_size < 1) { + return; + } + frame_size = next_lower_power_of_two(frame_size); unsigned char* temp = (unsigned char*)volk_malloc(sizeof(unsigned char) * frame_size, volk_get_alignment()); @@ -126,6 +142,10 @@ volk_8u_x3_encodepolarpuppet_8u_a_avx2(unsigned char* frame, const unsigned char* info_bits, unsigned int frame_size) { + if (frame_size < 1) { + return; + } + frame_size = next_lower_power_of_two(frame_size); unsigned char* temp = (unsigned char*)volk_malloc(sizeof(unsigned char) * frame_size, volk_get_alignment()); From a279d234aa9f64db977b3edbd010af1436a9320f Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Sun, 22 Oct 2023 13:37:57 -0400 Subject: [PATCH 2/2] Add carriage return to error message Signed-off-by: Clayton Smith --- lib/volk_malloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/volk_malloc.c b/lib/volk_malloc.c index 27fb699ce..8840fc3ff 100644 --- a/lib/volk_malloc.c +++ b/lib/volk_malloc.c @@ -38,7 +38,7 @@ void* volk_malloc(size_t size, size_t alignment) { if ((size == 0) || (alignment == 0)) { - fprintf(stderr, "VOLK: Error allocating memory: either size or alignment is 0"); + fprintf(stderr, "VOLK: Error allocating memory: either size or alignment is 0\n"); return NULL; } // Tweak size to satisfy ASAN (the GCC address sanitizer).