Skip to content
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

lib: Fix out-of-bounds array access in i.atcorr/computations.cpp #3909

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ShubhamDesai
Copy link
Contributor

@ShubhamDesai ShubhamDesai commented Jun 19, 2024

This pull request fixes several instances of out-of-bounds array access in the computations.cpp file within the i.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

  • Added a condition to ensure kk is not negative before using it as an array index.
    if (kk < 0) kk = 0;

Issues Resolved

  1. 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])) /

  2. Error : Assuming condition is false
    Location : imagery/i.atcorr/computations.cpp:110:20
    Details : if (rmu[i] > 0.94)

  3. Error : Assignment 'kk=i-1', assigned value is -1
    Location : imagery/i.atcorr/computations.cpp:112:16
    Details : kk = i - 1;

  4. Error : Negative array index
    Location : imagery/i.atcorr/computations.cpp:116:39
    Details : (double)((log10(sixs_trunc.pha[kk]) - log10(sixs_trunc.pha[k])) /

  5. 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])));

  6. Error : Assuming condition is false
    Location : imagery/i.atcorr/computations.cpp:110:20
    Details : if (rmu[i] > 0.94)

  7. Error : Assignment 'kk=i-1', assigned value is -1
    Location : imagery/i.atcorr/computations.cpp:112:16
    Details : kk = i - 1;

  8. Error : Negative array index
    Location : imagery/i.atcorr/computations.cpp:117:27
    Details : (acos(rmu[kk]) - acos(rmu[k])));

  9. 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]));

  10. Error : Assuming condition is false
    Location : imagery/i.atcorr/computations.cpp:110:20
    Details : if (rmu[i] > 0.94)

  11. Error : Assignment 'kk=i-1', assigned value is -1
    Location : imagery/i.atcorr/computations.cpp:112:16
    Details : kk = i - 1;

  12. Error : Negative array index
    Location : imagery/i.atcorr/computations.cpp:118:46
    Details : double x1 = (double)(log10(sixs_trunc.pha[kk]));

  13. 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]);

  14. Error : Assuming condition is false
    Location : imagery/i.atcorr/computations.cpp:110:20
    Details : if (rmu[i] > 0.94)

  15. Error : Assignment 'kk=i-1', assigned value is -1
    Location : imagery/i.atcorr/computations.cpp:112:16
    Details : kk = i - 1;

  16. Error : Negative array index
    Location : imagery/i.atcorr/computations.cpp:119:33
    Details : double x2 = (double)acos(rmu[kk]);

@github-actions github-actions bot added C++ Related code is in C++ module imagery labels Jun 20, 2024
ShubhamDesai and others added 3 commits June 19, 2024 22:52
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@nilason nilason requested a review from YannChemin July 4, 2024 21:52
@nilason nilason added this to the 8.5.0 milestone Jul 4, 2024
@nilason
Copy link
Contributor

nilason commented Jul 9, 2024

@YannChemin Would this minor change to i.atcorr lead to any unintended consequences?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ Related code is in C++ imagery module
3 participants