-
-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i.atcorr: Fix out-of-bounds array access in trunca computations #3909
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@YannChemin Would this minor change to |
@ShubhamDesai Check this suggestion from ChatGPT: https://chatgpt.com/share/66f18923-0348-8009-bf2a-e415c5ae9a89 With or without that suggestion, this PS seems like it will require a regression test to make sure we are not breaking this. Can you write one in a separate PR? Either pytest style you used before for g.version (but with use of, e.g., r.univar to get raster values) or it might be easier to follow the unittest style with existing dataset like e.g., https://github.com/OSGeo/grass/blob/main/vector/v.surf.rst/testsuite/test_vsurfrst.py (check the assertVectorFitsUnivar calls). We can discuss in more detail when we meet. |
Sure I will write the regression test for it. |
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]);