Skip to content

Commit

Permalink
i.maxlik: fix crash when classification result is NULL (OSGeo#2724)
Browse files Browse the repository at this point in the history
If any input cell from imagery group is NULL, the result of classification is also NULL. The implementation of original cat restoration (79f9500) did not check for this corner case and thus caused an out of bounds value access.
  • Loading branch information
marisn authored and ninsbl committed Feb 17, 2023
1 parent 1a65d93 commit f0acd20
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion imagery/i.maxlik/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ int main(int argc, char *argv[])
for (int col = 0; col < ncols; col++) {
/* Predicted classes start at 1 but signature array is 0 based
*/
class_cell[col] = S.sig[class_cell[col] - 1].oclass;
if (Rast_is_c_null_value(&class_cell[col]) == 0)
class_cell[col] = S.sig[class_cell[col] - 1].oclass;
}
}
Rast_put_row(class_fd, class_cell, CELL_TYPE);
Expand Down
2 changes: 1 addition & 1 deletion imagery/i.maxlik/testsuite/test_i_maxlik.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def setUpClass(cls):
)
cls.runModule(
"r.mapcalc",
expression=f"{cls.b2}=5.0+rand(-1.0,1.0)",
expression=f"{cls.b2}=if(row() == 3 && col() == 3, null(), 5.0+rand(-1.0,1.0))",
flags="s",
quiet=True,
)
Expand Down

0 comments on commit f0acd20

Please sign in to comment.