-
-
Notifications
You must be signed in to change notification settings - Fork 311
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 bound access in trunca, os and iso #4493
Conversation
I want someone familiar with the implementation details to review this and see if this is alright. Most of the variables changed here are internal variables and are specific to the implementation. Thanks! |
The original code has been written in Fortran which uses 1 based indices. During translation to C, not everything was translated properly, particularly the adjusted of 1 based indices to zero-based indices. The correct fix would probably be to use |
In trunca(), under 2 if conditionals (if rumu[1] > 0.8 and rmu[1] > 0.94), k and kk values are set to -1 respectively. When these values are used to access an array, it leads to out of bound access, which is undefined behavior in c++. Similarly in os() and iso(), if `taup < h[i]` for all values, iplane would still be -1 and we would be accessing an array with this as an index, which is undefined behavior. In both cases, to avoid that, set that index to zero. This was found using cppcheck tool. Signed-off-by: Mohan Yelugoti <[email protected]>
998d777
to
f6c77de
Compare
Made changes to reflect the suggestions. |
When plane layer couldn't be determined, throw out an error and exit. Co-authored-by: Markus Metz <[email protected]>
When plane layer couldn't be determined, throw out an error and exit. Co-authored-by: Markus Metz <[email protected]>
Signed-off-by: Mohan Yelugoti <[email protected]>
ae8b939
to
e1c7688
Compare
I'll proxy the approval once it passes later tonight |
In
trunca()
, under 2 if conditionals (if rumu[1] > 0.8 and rmu[1] > 0.94
), k and kk values are set to-1
respectively. When these values are used to access an array, it leads to out of bound access, which is undefined behavior in c++.Similarly in
os()
andiso()
, iftaup < h[i]
for all values, iplane would still be-1
and we would be accessing an array with this as an index, which is undefined behavior.In both cases, to avoid that, set that index to zero.
This was found using cppcheck tool.