lib: Fix out-of-bounds array access in i.atcorr/computations.cpp #3909
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.
This pull request fixes several instances of out-of-bounds array access in the
computations.cpp
file within thei.atcorr
module. Specifically, it addresses issues where negative indices were being used to access arrays, which could lead to undefined behavior and potential crashes.Changes Made
if (kk < 0) kk = 0;
Issues Resolved
Error : Array sixs_trunc.pha[83] accessed at index -1, which is out of bounds.
Location : imagery/i.atcorr/computations.cpp:116:39
Details : (double)((log10(sixs_trunc.pha[kk]) - log10(sixs_trunc.pha[k])) /
Error : Assuming condition is false
Location : imagery/i.atcorr/computations.cpp:110:20
Details : if (rmu[i] > 0.94)
Error : Assignment 'kk=i-1', assigned value is -1
Location : imagery/i.atcorr/computations.cpp:112:16
Details : kk = i - 1;
Error : Negative array index
Location : imagery/i.atcorr/computations.cpp:116:39
Details : (double)((log10(sixs_trunc.pha[kk]) - log10(sixs_trunc.pha[k])) /
Error : Array rmu[83] accessed at index -1, which is out of bounds.
Location : imagery/i.atcorr/computations.cpp:117:27
Details : (acos(rmu[kk]) - acos(rmu[k])));
Error : Assuming condition is false
Location : imagery/i.atcorr/computations.cpp:110:20
Details : if (rmu[i] > 0.94)
Error : Assignment 'kk=i-1', assigned value is -1
Location : imagery/i.atcorr/computations.cpp:112:16
Details : kk = i - 1;
Error : Negative array index
Location : imagery/i.atcorr/computations.cpp:117:27
Details : (acos(rmu[kk]) - acos(rmu[k])));
Error : Array sixs_trunc.pha[83] accessed at index -1, which is out of bounds.
Location : imagery/i.atcorr/computations.cpp:118:46
Details : double x1 = (double)(log10(sixs_trunc.pha[kk]));
Error : Assuming condition is false
Location : imagery/i.atcorr/computations.cpp:110:20
Details : if (rmu[i] > 0.94)
Error : Assignment 'kk=i-1', assigned value is -1
Location : imagery/i.atcorr/computations.cpp:112:16
Details : kk = i - 1;
Error : Negative array index
Location : imagery/i.atcorr/computations.cpp:118:46
Details : double x1 = (double)(log10(sixs_trunc.pha[kk]));
Error : Array rmu[83] accessed at index -1, which is out of bounds.
Location : imagery/i.atcorr/computations.cpp:119:33
Details : double x2 = (double)acos(rmu[kk]);
Error : Assuming condition is false
Location : imagery/i.atcorr/computations.cpp:110:20
Details : if (rmu[i] > 0.94)
Error : Assignment 'kk=i-1', assigned value is -1
Location : imagery/i.atcorr/computations.cpp:112:16
Details : kk = i - 1;
Error : Negative array index
Location : imagery/i.atcorr/computations.cpp:119:33
Details : double x2 = (double)acos(rmu[kk]);