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

i.atcorr: fix out of bound access in trunca, os and iso #4493

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions imagery/i.atcorr/computations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ double trunca()
for (i = 0; i < 83; i++) {
if (rmu[i] > 0.8)
break;
k = i - 1;
k = i;
}

int kk = 0;
for (i = 0; i < 83; i++) {
if (rmu[i] > 0.94)
break;
kk = i - 1;
kk = i;
}

double aa =
Expand All @@ -118,7 +118,7 @@ double trunca()
double x1 = (double)(log10(sixs_trunc.pha[kk]));
double x2 = (double)acos(rmu[kk]);

for (i = kk + 1; i < 83; i++) {
for (i = kk; i < 83; i++) {
double a;
if (fabs(rmu[i] - 1) <= 1e-08)
a = x1 - aa * x2;
Expand Down Expand Up @@ -445,9 +445,14 @@ void os(const double tamoy, const double trmoy, const double pizmoy,
/* compute position of the plane layer */
double taup = tap + trp;
iplane = -1;
for (int i = 0; i <= ntp; i++)
for (int i = 0; i <= ntp; i++) {
if (taup >= h[i])
iplane = i;
}
if (iplane == -1) {
G_fatal_error(
_("Position of the plane layer could not be determined"));
}

/* update the layer from the end to the position to update if necessary
*/
Expand Down Expand Up @@ -1006,9 +1011,14 @@ void iso(const double tamoy, const double trmoy, const double pizmoy,
/* compute position of the plane layer */
double taup = tap + trp;
iplane = -1;
for (int i = 0; i <= ntp; i++)
for (int i = 0; i <= ntp; i++) {
if (taup >= h[i])
iplane = i;
}
if (iplane == -1) {
G_fatal_error(
_("Position of the plane layer could not be determined"));
}

/* update the layer from the end to the position to update if necessary
*/
Expand Down
Loading