[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 1570d28a: MakeCatalog: added check to avoid ob
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 1570d28a: MakeCatalog: added check to avoid objects images with negative values |
Date: |
Wed, 13 Apr 2022 08:39:46 -0400 (EDT) |
branch: master
commit 1570d28a44197baff5713356b24bc28177d93f18
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
MakeCatalog: added check to avoid objects images with negative values
Until now, when MakeCatalog was given an input (labeled) image that
contained negative values, it would crash with a segmentation fault
(because the negative pixels in an un-signed array index would lead to
extremely large values).
With this commit, on the first time that we parse the input object labels,
if we find a non-blank negative pixels in the image, an informative warning
is printed and MakeCatalog aborts cleanly.
This bug was reported by Sepideh Eskandarlou.
This fixes bug #62309.
---
NEWS | 3 +++
bin/mkcatalog/ui.c | 53 ++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 39 insertions(+), 17 deletions(-)
diff --git a/NEWS b/NEWS
index 986ef884..a2a3c0b5 100644
--- a/NEWS
+++ b/NEWS
@@ -51,6 +51,9 @@ See the end of the file for license conditions.
bug #62305: Not reading the 'MemFree' keyword in '/proc/meminfo' to find
the available RAM (and thus printing an annoying
warning). Reported by Juan Miro.
+ bug #62309: MakeCatalog segmentation fault when clumps image given as
+ main input (objects should be given). Reported by Sepideh
+ Eskandarlou.
diff --git a/bin/mkcatalog/ui.c b/bin/mkcatalog/ui.c
index 50b0653a..c3c4dadf 100644
--- a/bin/mkcatalog/ui.c
+++ b/bin/mkcatalog/ui.c
@@ -686,23 +686,42 @@ ui_one_tile_per_object_correct_numobjects(struct
mkcatalogparams *p)
start=p->objects->array;
lf=(l=p->objects->array)+p->objects->size;
do
- if(*l>0)
- {
- /* Get the coordinates of this pixel. */
- gal_dimension_index_to_coord(l-start, ndim, p->objects->dsize,
- coord);
-
- /* Check to see this coordinate is the smallest/largest found so
- far for this label. Note that labels start from 1, while indexs
- here start from zero. */
- min = &minmax[ (*l-1) * width ];
- max = &minmax[ (*l-1) * width + ndim ];
- for(d=0;d<ndim;++d)
- {
- if( coord[d] < min[d] ) min[d] = coord[d];
- if( coord[d] > max[d] ) max[d] = coord[d];
- }
- }
+ {
+ /* Small sanity check: the objects image shouldn't have negative
+ values (can happen when the user gives a clump image). */
+ if(*l!=GAL_BLANK_INT32 && *l<0)
+ error(EXIT_FAILURE, 0, "the main labeled image ('OBJECTS' HDU "
+ "when using Segment), shouldn't contain negative values. "
+ "This can happen when you mistakenly give Segment's "
+ "clumps as the main input labeled image. If you want to "
+ "treat clumps as objects, please use 'astarithmetic' to "
+ "convert all negative pixels to 0 before calling "
+ "MakeCatalog. For example this command: "
+ "'astarithmetic file.fits -hCLUMPS set-i i i 0 lt "
+ "0 where'. For this scenario, a better solution is to "
+ "only keep the clumps and give them each a separate "
+ "label with a command like this: 'astarithmetic file.fits "
+ "-hCLUMPS set-i i i 0 gt 2 connected-components'");
+
+ /* We are on an object. */
+ if(*l>0)
+ {
+ /* Get the coordinates of this pixel. */
+ gal_dimension_index_to_coord(l-start, ndim, p->objects->dsize,
+ coord);
+
+ /* Check to see this coordinate is the smallest/largest found so
+ far for this label. Note that labels start from 1, while indexs
+ here start from zero. */
+ min = &minmax[ (*l-1) * width ];
+ max = &minmax[ (*l-1) * width + ndim ];
+ for(d=0;d<ndim;++d)
+ {
+ if( coord[d] < min[d] ) min[d] = coord[d];
+ if( coord[d] > max[d] ) max[d] = coord[d];
+ }
+ }
+ }
while(++l<lf);
/* If a label doesn't exist in the image, then write over it and define
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master 1570d28a: MakeCatalog: added check to avoid objects images with negative values,
Mohammad Akhlaghi <=