Opened 4 years ago

Closed 4 years ago

#3249 closed defect (fixed)

v.what.rast: segfault with map without topology

Reported by: sbl Owned by: martinl
Priority: normal Milestone: 7.2.1
Component: Vector Version: svn-trunk
Keywords: v.what.rast, level 1 Cc: grass-dev@…
CPU: Unspecified Platform: Unspecified

Description (last modified by martinl)

Recently the requirement for topology was removed from v.what.rast.

However, the module now segfaults if used with a vector map without topology.

The issue can be reproduced with the workflow and data in #3248, but with

v.external -b

Related discussion here: https://lists.osgeo.org/pipermail/grass-dev/2017-January/083830.html

Attachments (1)

v_what_rast_level1.diff (2.0 KB) - added by martinl 4 years ago.

Download all attachments as: .zip

Change History (19)

comment:1 Changed 4 years ago by martinl

Description: modified (diff)
Keywords: v. external added

comment:2 Changed 4 years ago by martinl

Cc: grass-dev@… added
Owner: changed from grass-dev@… to martinl
Status: newassigned

comment:3 Changed 4 years ago by martinl

Component: DefaultVector
Keywords: PostGIS added

comment:4 Changed 4 years ago by martinl

Description: modified (diff)

comment:5 Changed 4 years ago by martinl

It's not issue only for linked maps, but also for native format

v.random out=pn n=1000 -b --o column=z
v.what.rast map=pn raster=rand column=morphology
Column <morphology> not found in the table <pn>. Creating...
Reading features from vector map...

Segmentation fault

comment:6 Changed 4 years ago by martinl

Keywords: level 1 added; v. external PostGIS removed

comment:7 Changed 4 years ago by martinl

Seems to be a stack overflow somewhere since Map_info struct got ruined before segfault:

gdb) p Map.dblnk->field[0]
$11 = {number = 6, name = 0x7600000344 <error: Cannot access memory at address 0x7600000344>, driver = 0x60d770 "sqlite", database = 0x642100 "$GISDBASE/$LOCAT\005", table = 0x60d5f0 "pn18", key = 0x60d6b0 "cat"}
#0  _int_malloc (av=av@entry=0x7ffff6f86b00 <main_arena>, bytes=bytes@entry=26) at malloc.c:3762
#1  0x00007ffff6c68d94 in __GI___libc_malloc (bytes=26) at malloc.c:2925
#2  0x00007ffff729e088 in G__malloc (file=0x7ffff72e166b "lib/gis/location.c", line=82, n=26) at alloc.c:39
#3  0x00007ffff72aa7c1 in G__location_path () at location.c:82
#4  0x00007ffff72a4aaa in file_name (path=0x7fffffff9990 "\001", dir=0x0, element=0x7fffffffae00 "vector/pn17", name=0x7ffff7bc2ed7 "dbln", mapset=0x6095f0 "PERMANENT", base=0x0)
    at file_name.c:107
#5  0x00007ffff72a4963 in G_file_name (path=0x7fffffff9990 "\001", element=0x7fffffffae00 "vector/pn17", name=0x7ffff7bc2ed7 "dbln", mapset=0x6095f0 "PERMANENT") at file_name.c:41
#6  0x00007ffff72c0743 in G__open (element=0x7fffffffae00 "vector/pn17", name=0x7ffff7bc2ed7 "dbln", mapset=0x6095f0 "PERMANENT", mode=1) at open.c:109
#7  0x00007ffff72c0929 in G_fopen_new (element=0x7fffffffae00 "vector/pn17", name=0x7ffff7bc2ed7 "dbln") at open.c:224
#8  0x00007ffff7b7ddcc in Vect_write_dblinks (Map=0x7fffffffbf40) at field.c:923
#9  0x00007ffff7b7e395 in Vect_set_db_updated (Map=0x7fffffffbf40) at field.c:1023
#10 0x00000000004027bc in main (argc=4, argv=0x7fffffffd9e8) at main.c:251

comment:8 Changed 4 years ago by martinl

Milestone: 7.2.17.4.0

Since changes in v.what.rast (r70331+r70332) haven't been ported to relbr72, setting milestone to 7.4.0.

comment:9 Changed 4 years ago by marisn

When ever there seems to be a problem with memory, use valgrind!

The reason of segfault is a failure to allocate memory on line 197. It comes from call to Vect_get_num_primitives few lines earlier. Vect_get_num_primitives uses Map.plus to get info about number of features, but plus "Holds basic topology-related information about vector map". No topology == no number of features in plus == allocation of 0 sized memory for cache == illegal writes further in code.

Solution:

  • information about number of features must be obtained in some other way (L194)
  • probably also Vect_get_num_primitives should be modified to return -1 if topology is missing

comment:10 Changed 4 years ago by martinl

In 70366:

v.what.rast: require level 2 (see #3249)

comment:11 in reply to:  9 ; Changed 4 years ago by martinl

  • probably also Vect_get_num_primitives should be modified to return -1 if topology is missing

Or the routine could return number of primitives by reading all features, this issue is related conceptually with #3244. For now I changed module back to require level2 (r70366).

comment:12 in reply to:  11 ; Changed 4 years ago by martinl

Replying to martinl:

  • probably also Vect_get_num_primitives should be modified to return -1 if topology is missing

Or the routine could return number of primitives by reading all features, this issue is related conceptually with #3244. For now I changed module back to require level2 (r70366).

Anyway in this case it doesn't make sense since features would be read twice by the module. Probably best way could be allocating cache dynamically on level 1. I will try to provide patch in the next days.

comment:13 in reply to:  12 Changed 4 years ago by martinl

Replying to martinl:

Anyway in this case it doesn't make sense since features would be read twice by the module. Probably best way could be allocating cache dynamically on level 1. I will try to provide patch in the next days.

See attachment:v_what_rast_level1.diff. If no objection I will commit into trunk.

Changed 4 years ago by martinl

Attachment: v_what_rast_level1.diff added

comment:14 in reply to:  9 Changed 4 years ago by martinl

Replying to marisn:

The reason of segfault is a failure to allocate memory on line 197. It comes from call to Vect_get_num_primitives few lines earlier. Vect_get_num_primitives uses Map.plus to get info about number of features, but plus "Holds basic topology-related information about vector map". No topology == no number of features in plus == allocation of 0 sized memory for cache == illegal writes further in code.

Thanks for your time and investigation.

comment:15 Changed 4 years ago by martinl

In 70381:

v.what.rast: segfault with map without topology (see #3249)

comment:16 Changed 4 years ago by martinl

Support for level 1 implemented in trunk r70381. If no objection I will backport to relbr72.

comment:17 Changed 4 years ago by martinl

Milestone: 7.4.07.2.1

comment:18 Changed 4 years ago by martinl

Resolution: fixed
Status: assignedclosed

In 70425:

v.what.rast: segfault with map without topology (fix #3249)

(merge r70331, r70332, r70366, r70381 from trunk)

Note: See TracTickets for help on using tickets.