powturbo / TurboPFor-Integer-Compression

Fastest Integer Compression
GNU General Public License v2.0
770 stars 112 forks source link

Access violation reading elements past the end of the array in transcode.c #89

Closed pps83 closed 1 year ago

pps83 commented 1 year ago

When compiling with clang I get tons of warnings accessing elements past the end of the array bounds inside transcode.c

Looking into specifics of the warnings, I think all of them are legit bugs that should be addressed. All of the warnings are related to ov variables declared on lines 603, 731, 849, 1107. For example, when compiling AVX version I get these warnings:

Build started...
1>------ Build started: Project: TurboPFor, Configuration: Release x64 ------
1>In file included from ..\transpose_avx2.c:2:
1>In file included from ../../transpose.c:94:
1>../../transpose.c(681,5): warning : array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(603,5): message : array 'ov' declared here
1>../../transpose.c(681,122): warning : array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(603,5): message : array 'ov' declared here
1>../../transpose.c(681,132): warning : array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(603,5): message : array 'ov' declared here
1>../../transpose.c(681,63): warning : array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(603,5): message : array 'ov' declared here
1>../../transpose.c(681,171): warning : array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(675,83): message : expanded from macro 'mm256_packus_epi16'
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\lib\clang\15.0.1\include\avx2intrin.h(818,56): message : expanded from macro '_mm256_permute4x64_epi64'
1>../../transpose.c(603,5): message : array 'ov' declared here
1>../../transpose.c(681,144): warning : array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(603,5): message : array 'ov' declared here
1>../../transpose.c(682,5): warning : array index 3 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(603,5): message : array 'ov' declared here
1>../../transpose.c(682,122): warning : array index 3 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(603,5): message : array 'ov' declared here
1>../../transpose.c(682,132): warning : array index 3 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(603,5): message : array 'ov' declared here
1>../../transpose.c(682,63): warning : array index 3 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(603,5): message : array 'ov' declared here
1>../../transpose.c(682,171): warning : array index 3 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(675,83): message : expanded from macro 'mm256_packus_epi16'
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\lib\clang\15.0.1\include\avx2intrin.h(818,56): message : expanded from macro '_mm256_permute4x64_epi64'
1>../../transpose.c(603,5): message : array 'ov' declared here
1>../../transpose.c(682,144): warning : array index 3 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(603,5): message : array 'ov' declared here
1>../../transpose.c(683,49): warning : array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(676,97): message : expanded from macro 'ST128'
1>../../transpose.c(603,5): message : array 'ov' declared here
1>../../transpose.c(683,67): warning : array index 3 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(676,97): message : expanded from macro 'ST128'
1>../../transpose.c(603,5): message : array 'ov' declared here
1>../../transpose.c(734,16): warning : array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(712,19): message : expanded from macro 'NBL'
1>../../transpose.c(731,5): message : array 'ov' declared here
1>../../transpose.c(734,16): warning : array index 3 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(713,19): message : expanded from macro 'NBL'
1>../../transpose.c(731,5): message : array 'ov' declared here
1>../../transpose.c(734,42): warning : array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(716,74): message : expanded from macro 'NB'
1>../../transpose.c(731,5): message : array 'ov' declared here
1>../../transpose.c(734,42): warning : array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(716,49): message : expanded from macro 'NB'
1>../../transpose.c(731,5): message : array 'ov' declared here
1>../../transpose.c(734,42): warning : array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(716,3): message : expanded from macro 'NB'
1>../../transpose.c(731,5): message : array 'ov' declared here
1>../../transpose.c(734,42): warning : array index 3 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(717,74): message : expanded from macro 'NB'
1>../../transpose.c(731,5): message : array 'ov' declared here
1>../../transpose.c(734,42): warning : array index 3 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(717,49): message : expanded from macro 'NB'
1>../../transpose.c(731,5): message : array 'ov' declared here
1>../../transpose.c(734,42): warning : array index 3 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(717,3): message : expanded from macro 'NB'
1>../../transpose.c(731,5): message : array 'ov' declared here
1>../../transpose.c(734,42): warning : array index 3 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(718,45): message : expanded from macro 'NB'
1>../../transpose.c(731,5): message : array 'ov' declared here
1>../../transpose.c(734,42): warning : array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
1>../../transpose.c(718,55): message : expanded from macro 'NB'
1>../../transpose.c(731,5): message : array 'ov' declared here
1>Done building project "TurboPFor.vcxproj".
pps83 commented 1 year ago

VS2022 also issues these errors:

C:\work-pps\TurboPFor\transpose.c(682): error C4789: buffer 'ov' of size 64 bytes will be overrun; 32 bytes will be written starting at offset 96
C:\work-pps\TurboPFor\transpose.c(682): error C4789: buffer 'ov' of size 64 bytes will be overrun; 32 bytes will be written starting at offset 96
C:\work-pps\TurboPFor\transpose.c(682): error C4789: buffer 'ov' of size 64 bytes will be overrun; 32 bytes will be written starting at offset 96
C:\work-pps\TurboPFor\transpose.c(681): error C4789: buffer 'ov' of size 64 bytes will be overrun; 32 bytes will be written starting at offset 64
C:\work-pps\TurboPFor\transpose.c(681): error C4789: buffer 'ov' of size 64 bytes will be overrun; 32 bytes will be written starting at offset 64
C:\work-pps\TurboPFor\transpose.c(681): error C4789: buffer 'ov' of size 64 bytes will be overrun; 32 bytes will be written starting at offset 64
C:\work-pps\TurboPFor\transpose.c(734): error C4789: buffer 'ov' of size 64 bytes will be overrun; 32 bytes will be written starting at offset 96
C:\work-pps\TurboPFor\transpose.c(734): error C4789: buffer 'ov' of size 64 bytes will be overrun; 32 bytes will be written starting at offset 64
C:\work-pps\TurboPFor\transpose.c(734): error C4789: buffer 'ov' of size 64 bytes will be overrun; 32 bytes will be written starting at offset 96
C:\work-pps\TurboPFor\transpose.c(734): error C4789: buffer 'ov' of size 64 bytes will be overrun; 32 bytes will be written starting at offset 64
C:\work-pps\TurboPFor\transpose.c(1069): error C4789: buffer 'ov' of size 32 bytes will be overrun; 16 bytes will be written starting at offset 48
C:\work-pps\TurboPFor\transpose.c(1069): error C4789: buffer 'ov' of size 32 bytes will be overrun; 16 bytes will be written starting at offset 48
C:\work-pps\TurboPFor\transpose.c(1069): error C4789: buffer 'ov' of size 32 bytes will be overrun; 16 bytes will be written starting at offset 48
C:\work-pps\TurboPFor\transpose.c(1068): error C4789: buffer 'ov' of size 32 bytes will be overrun; 16 bytes will be written starting at offset 32
C:\work-pps\TurboPFor\transpose.c(1068): error C4789: buffer 'ov' of size 32 bytes will be overrun; 16 bytes will be written starting at offset 32
C:\work-pps\TurboPFor\transpose.c(1068): error C4789: buffer 'ov' of size 32 bytes will be overrun; 16 bytes will be written starting at offset 32
C:\work-pps\TurboPFor\transpose.c(1120): error C4789: buffer 'ov' of size 32 bytes will be overrun; 16 bytes will be written starting at offset 48
C:\work-pps\TurboPFor\transpose.c(1120): error C4789: buffer 'ov' of size 32 bytes will be overrun; 16 bytes will be written starting at offset 48
C:\work-pps\TurboPFor\transpose.c(1119): error C4789: buffer 'ov' of size 32 bytes will be overrun; 16 bytes will be written starting at offset 32
C:\work-pps\TurboPFor\transpose.c(1119): error C4789: buffer 'ov' of size 32 bytes will be overrun; 16 bytes will be written starting at offset 32
C:\work-pps\TurboPFor\transpose.c(1113): error C4789: buffer 'ov' of size 32 bytes will be overrun; 16 bytes will be written starting at offset 48
C:\work-pps\TurboPFor\transpose.c(1112): error C4789: buffer 'ov' of size 32 bytes will be overrun; 16 bytes will be written starting at offset 32
powturbo commented 1 year ago

Thank you. I've made the changes. I've activated the warnings and it seems there are no more important warnings.