Fix #847: missing range checks in statespace_*.h files#848
Merged
Conversation
CodeQL scans flagged lines like 353 in `lib/statespace_avx512.h`, reporting that the use of offset `m` should follow the range check:
```C++
while (rs[m] < csum && m < num_samples) {
```
In more detail:
> The program contains an and-expression where the array access is defined before the range check. Consequently the array is accessed without any bounds checking. The range check does not protect the program from segmentation faults caused by attempts to read beyond the end of a buffer.
The same error exists in the following files:
* statespace_basic.h
* statespace_sse.h
* statespace_avx512.h
* statespace_avx.h
pavoljuhas
approved these changes
Aug 15, 2025
Collaborator
pavoljuhas
left a comment
There was a problem hiding this comment.
There seems to be one more such case:
diff --git a/lib/statespace_cuda_kernels.h b/lib/statespace_cuda_kernels.h
index b54ebca..0bc4ba7 100644
--- a/lib/statespace_cuda_kernels.h
+++ b/lib/statespace_cuda_kernels.h
@@ -318,5 +318,5 @@ __global__ void SampleKernel(unsigned num_blocks,
FP3 im = state[l + warp_size];
csum += re * re + im * im;
- while (rs[m] < csum && m < num_samples) {
+ while (m < num_samples && rs[m] < csum) {
bitstrings[m++] = k0 + k;
}
Otherwise LGTM.
Collaborator
Author
Thanks for catching that. |
Caught by @pavoljuhas in review.
Collaborator
Author
|
The latest commit has that fixed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CodeQL scans flagged lines like 353 in
lib/statespace_avx512.h, reporting that the use of offsetmshould follow the range check:while (rs[m] < csum && m < num_samples) {In more detail:
The same issue exists in the following files: