[GRASS-dev] [GRASS GIS] #175: v.to.rast labelcol= SegFault

#175: v.to.rast labelcol= SegFault
-----------------------+----------------------------------------------------
Reporter: hamish | Owner: grass-dev@lists.osgeo.org
     Type: defect | Status: new
Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Keywords: v.to.rast |
-----------------------+----------------------------------------------------
Hi,

v.to.rast segfaults with the labelcolumn= option:

{{{
#spearfish
G64> g.region -d
G64> v.to.rast in=fields out=fields.v2r labelcol=label col=cat
WARNING: Area without centroid (may be OK for island)
WARNING: Area without centroid (may be OK for island)
Converted areas: 65 of 65
Converted points/lines: 0 of 0
Segmentation fault
}}}

gdb:
{{{
#0 0xb791ef43 in strcpy () from /lib/tls/i686/cmov/libc.so.6
#1 0xb7f91793 in set_string (x=0xbf81d978, s=0x808c450 "\"NO DATA\"",
copy=1)
     at string.c:108
#2 0xb7f91681 in db_set_string (x=0xbf81d978, s=0x808c450 "\"NO DATA\"")
     at string.c:39
#3 0xb7f91a1c in db_copy_string (dst=0xbf81d978, src=0x808c3a0)
     at string.c:237
#4 0xb7f9276c in db_copy_value (dst=0xbf81d968, src=0x808c390) at
value.c:372
#5 0xb7efba1b in db_select_value (driver=0x808b2a0, tab=0x808af08
"fields",
     key=0x808af18 "cat", id=0, col=0x8057d88 "label", val=0xbf81d968)
     at select.c:195
#6 0x0804c571 in update_labels (rast_name=0x8057d78 "fields.v2r",
     vector_map=0x8057d68 "fields", field=1, label_column=0x8057d88
"label",
     use=1, val=1, attr_column=0x8057d98 "cat") at support.c:298
#7 0x0804d369 in vect_to_rast (vector_map=0x8057d68 "fields",
     raster_map=0x8057d78 "fields.v2r", field=1, column=0x8057d98 "cat",
     nrows=4096, use=1, value=1, value_type=1, rgbcolumn=0x0,
     labelcolumn=0x8057d88 "label", ftype=67) at vect2rast.c:212
#8 0x0804b1f7 in main (argc=7627107, argv=0xb79e2510) at main.c:135
}}}

Also when trying to use the vector cat for the raster cat the labelcolumn
is ignored:
{{{
G64> v.to.rast in=fields out=fields.v2r labelcol=label use=cat
WARNING: Area without centroid (may be OK for island)
WARNING: Area without centroid (may be OK for island)
Converted areas: 65 of 65
Converted points/lines: 0 of 0
[success]
G64> r.category fields.v2r
1 Category 1
2 Category 2
3 Category 3
4 Category 4
5 Category 5
6 Category 6
7 Category 7
...
}}}

ie the labelcolumn= is replaced by "Category n"
{{{
G64> v.db.select fields | head
cat|label
0|"NO DATA"
1|"C. Smith #1"
2|C. Smith#2
3|P. Biggam#1
4|P. Biggam#2
5|P. Biggam#3
6|P. Biggam#5
7|P. Biggam#6
8|P. Biggam#7
}}}

?

thanks,
Hamish

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/175&gt;
GRASS GIS <http://grass.osgeo.org>

#175: v.to.rast labelcol= SegFault
----------------------+-----------------------------------------------------
  Reporter: hamish | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: new
  Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Resolution: | Keywords: v.to.rast
----------------------+-----------------------------------------------------
Changes (by martinl):

* cc: martinl (added)

Comment:

Replying to [ticket:175 hamish]:
> v.to.rast segfaults with the labelcolumn= option:
>
> {{{
> #spearfish
> G64> g.region -d
> G64> v.to.rast in=fields out=fields.v2r labelcol=label col=cat
> WARNING: Area without centroid (may be OK for island)
> WARNING: Area without centroid (may be OK for island)
> Converted areas: 65 of 65
> Converted points/lines: 0 of 0
> Segmentation fault
> }}}

strange, I cannot reproduce segfault on my machine (GNU/Debian Unstable,
32bit, G64)

{{{
v.to.rast in=fields out=fields.v2r labelcol=label col=cat --o

r.category fields.v2r | head
1 "C. Smith #1"
2 C. Smith#2
3 P. Biggam#1
4 P. Biggam#2
5 P. Biggam#3
6 P. Biggam#5
7 P. Biggam#6
8 P. Biggam#7
9 G. Tandy#1
10 C. Mitchell#1
}}}

{{{
v.to.rast in=fields out=fields.v2r labelcol=label use=cat --o

r.category fields.v2r | head
1 Category 1
2 Category 2
3 Category 3
4 Category 4
5 Category 5
6 Category 6
7 Category 7
8 Category 8
9 Category 9
10 Category 10
}}}

Martin

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/175#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#175: v.to.rast labelcol= SegFault
----------------------+-----------------------------------------------------
  Reporter: hamish | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: new
  Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Resolution: | Keywords: v.to.rast
----------------------+-----------------------------------------------------
Comment (by hamish):

I still see it. 6.4svn, Debian/etch, 32bit P4.

Hamish

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/175#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#175: v.to.rast labelcol= SegFault
----------------------+-----------------------------------------------------
  Reporter: hamish | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: new
  Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Resolution: | Keywords: v.to.rast
----------------------+-----------------------------------------------------
Comment (by hamish):

perhaps a red herring:

in gdb frame # 2 the raster cat source string is:
{{{
   s=0x808c450 "\"NO DATA\""
}}}

note this is raster category 0. The vector map version of "fields" has a
cat 0, so maybe that's legal, albeit uncommon, vector cat value.

but more to the point, this is where/why it SegFaults:

lib/db/dbmi_client/select.c
{{{
   if ( count == 0 ) db_copy_value ( val, value );
   // ie copy(destination, source)
}}}

the destination memory address (val->s->string) is out of bounds. nalloc
is 48, which seems ok.

that variable is created in v.to.rast/support.c line 296 with:
   dbValue value;
and then passed to db_select_value().

dbValue is defined in include/dbmi.h:
{{{
  typedef struct _db_value {
     char isNull;
     int i;
     double d;
     dbString s;
     dbDateTime t;
  } dbValue;
...
  typedef struct _db_string {
     char *string;
     int nalloc;
  } dbString;
}}}

so that dbString is being used as a target without having been malloc'd
first? I am not sure where s->nalloc=48 gets set, that's a bit of a
mystery to me.

Hamish

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/175#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#175: v.to.rast labelcol= SegFault
----------------------+-----------------------------------------------------
  Reporter: hamish | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: new
  Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Resolution: | Keywords: v.to.rast
----------------------+-----------------------------------------------------
Comment (by msieczka):

Replying to [comment:3 hamish]:

> note this is raster category 0. The vector map version of "fields" has a
cat 0, so maybe that's > legal, albeit uncommon, vector cat value.

Sidenote - category 0 is definitely valid. Radim's words from 2006:

"'cat' 0 was introduced after v.digit and probably before QGIS-GRASS. The
reason was mapping of OGR FID (which can be 0) to GRASS cat." [1]

[1]http://www.nabble.com/forum/ViewPost.jtp?post=2422467&framed=y

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/175#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>

#175: v.to.rast labelcol= SegFaults and ignored
--------------------------+-------------------------------------------------
  Reporter: hamish | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: new
  Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Resolution: | Keywords: v.to.rast
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------
Changes (by hamish):

  * platform: => Unspecified
  * cpu: => Unspecified
  * summary: v.to.rast labelcol= SegFault => v.to.rast labelcol= SegFaults
              and ignored

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/175#comment:5&gt;
GRASS GIS <http://grass.osgeo.org>

#175: v.to.rast labelcol= SegFaults and ignored
--------------------------+-------------------------------------------------
  Reporter: hamish | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: new
  Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Resolution: | Keywords: v.to.rast
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------
Comment (by mmetz):

Replying to [ticket:175 hamish]:
> Hi,
>
> v.to.rast segfaults with the labelcolumn= option:

{{{
#spearfish
G64> g.region -d
G64> v.to.rast in=fields out=fields.v2r labelcol=label col=cat
WARNING: Area without centroid (may be OK for island)
WARNING: Area without centroid (may be OK for island)
Converted areas: 65 of 65
Converted points/lines: 0 of 0
Segmentation fault
}}}

I get the segfault too with the above command, but not with

{{{
v.to.rast in=fields out=fields.v2r labelcol=label use=cat
}}}

The labels of fields.v2r are wrong, they read like

1:Category 1

Category 0 is now skipped ???

Altogether strange behaviour of v.to.rast...

I used devbr6

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/175#comment:6&gt;
GRASS GIS <http://grass.osgeo.org>

#175: v.to.rast labelcol= SegFaults and ignored
--------------------------+-------------------------------------------------
  Reporter: hamish | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: new
  Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Resolution: | Keywords: v.to.rast
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------
Comment (by martinl):

Replying to [ticket:175 hamish]:

{{{
> #spearfish
> G64> g.region -d
> G64> v.to.rast in=fields out=fields.v2r labelcol=label col=cat
> WARNING: Area without centroid (may be OK for island)
> WARNING: Area without centroid (may be OK for island)
> Converted areas: 65 of 65
> Converted points/lines: 0 of 0
> Segmentation fault
}}}

hopefully fixed in r39510.

Martin

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/175#comment:7&gt;
GRASS GIS <http://grass.osgeo.org>

#175: v.to.rast labelcol= SegFaults and ignored
--------------------------+-------------------------------------------------
  Reporter: hamish | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: new
  Priority: major | Milestone: 6.4.0
Component: Vector | Version: unspecified
Resolution: | Keywords: v.to.rast
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------
Changes (by martinl):

  * component: default => Vector

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/175#comment:8&gt;
GRASS GIS <http://grass.osgeo.org>

#175: v.to.rast labelcol= SegFaults and ignored
--------------------------+-------------------------------------------------
  Reporter: hamish | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: new
  Priority: major | Milestone: 6.4.0
Component: Vector | Version: unspecified
Resolution: | Keywords: v.to.rast
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------
Comment (by neteler):

I can confirm that it is fixed on Ubuntu 8.04/64bit.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/175#comment:9&gt;
GRASS GIS <http://grass.osgeo.org>

#175: v.to.rast labelcol= SegFaults and ignored
--------------------------+-------------------------------------------------
  Reporter: hamish | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: closed
  Priority: major | Milestone: 6.4.0
Component: Vector | Version: unspecified
Resolution: fixed | Keywords: v.to.rast
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------
Changes (by martinl):

  * status: new => closed
  * resolution: => fixed

Comment:

Replying to [comment:9 neteler]:
> I can confirm that it is fixed on Ubuntu 8.04/64bit.

Closing the ticket, please re-open if needed. Martin

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/175#comment:10&gt;
GRASS GIS <http://grass.osgeo.org>

#175: v.to.rast labelcol= SegFaults and ignored
--------------------------+-------------------------------------------------
  Reporter: hamish | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: reopened
  Priority: normal | Milestone: 6.4.0
Component: Vector | Version: unspecified
Resolution: | Keywords: v.to.rast
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------
Changes (by hamish):

  * priority: major => normal
  * status: closed => reopened
  * resolution: fixed =>

Comment:

Yes, r39510 does fix the segfault. thanks!
(tested before and after svn up)

The second item: ''Also when trying to use the vector cat for the raster
cat the labelcolumn is ignored'' remains unfixed, so reopening the report
for that.

cheers,
Hamish

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/175#comment:11&gt;
GRASS GIS <http://grass.osgeo.org>

#175: v.to.rast labelcol= SegFaults and ignored
--------------------------+-------------------------------------------------
  Reporter: hamish | Owner: grass-dev@…
      Type: defect | Status: reopened
  Priority: normal | Milestone: 6.4.0
Component: Vector | Version: unspecified
Resolution: | Keywords: v.to.rast
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------

Comment(by mmetz):

Replying to [comment:11 hamish]:
>
> The second item: ''Also when trying to use the vector cat for the raster
cat the labelcolumn is ignored'' remains unfixed, so reopening the report
for that.

Please try trunk r51970.

Markus M

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/175#comment:12&gt;
GRASS GIS <http://grass.osgeo.org>

#175: v.to.rast labelcol= SegFaults and ignored
--------------------------+-------------------------------------------------
  Reporter: hamish | Owner: grass-dev@…
      Type: defect | Status: reopened
  Priority: normal | Milestone: 6.4.0
Component: Vector | Version: unspecified
Resolution: | Keywords: v.to.rast
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------

Comment(by neteler):

Should this be backported?

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/175#comment:13&gt;
GRASS GIS <http://grass.osgeo.org>

#175: v.to.rast labelcol= SegFaults and ignored
--------------------------+-------------------------------------------------
  Reporter: hamish | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 6.4.3
Component: Vector | Version: unspecified
Resolution: fixed | Keywords: v.to.rast
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------
Changes (by hamish):

  * status: reopened => closed
  * resolution: => fixed
  * milestone: 6.4.0 => 6.4.3

Comment:

backported by mmetz to devbr6 and relbr64 in r52032 and r52703.

both issues tested ok in 6.4.3svn.

thanks,
Hamish

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/175#comment:14&gt;
GRASS GIS <http://grass.osgeo.org>