[GRASS-dev] [GRASS GIS] #3412: r.compress -u segfault

#3412: r.compress -u segfault
------------------------+---------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.2.2
Component: Default | Version: svn-releasebranch72
Keywords: r.compress | CPU: Unspecified
Platform: Linux |
------------------------+---------------------------------
When trying to uncompress a map, r.compress segfaults:

{{{
## GRASS 7.2.2svn (nc_spm_08_grass7):~ >
r.compress -u elev_lid792_1m_viewshed
Segmentation fault (core dumped)
}}}

Map info:
{{{
r.info elev_lid792_1m_viewshed
+----------------------------------------------------------------------------+
  | Map: elev_lid792_1m_viewshed Date: Fri Jul 29 13:45:27 2016
|
  | Mapset: user1 Login of Creator: mneteler
|
  | Location: nc_spm_08_grass7
|
  | DataBase: /home/mneteler/grassdata
|
  | Title:
|
  | Timestamp: none
|
|----------------------------------------------------------------------------|
  |
|
  | Type of Map: raster Number of Categories: 0
|
  | Data Type: FCELL
|
  | Rows: 750
|
  | Columns: 700
|
  | Total Cells: 525000
|
  | Projection: Lambert Conformal Conic
|
  | N: 220750 S: 220000 Res: 1
|
  | E: 639000 W: 638300 Res: 1
|
  | Range of data: min = 11.29489 max = 180
|
  |
|
  | Data Description:
|
  | generated by r.viewshed
|
  |
|
  | Comments:
|
  | r.viewshed --overwrite input="elev_lid792_1m"
output="elev_lid792_1m\ |
  | _viewshed" coordinates=638728.087167,220609.261501
observer_elevatio\ |
  | n=5.0 target_elevation=0.0 max_distance=-1 refraction_coeff=0.14286
\ |
  | memory=500
|
  |
|
+----------------------------------------------------------------------------+
}}}

And GDB debugging:
{{{
GRASS 7.2.2svn (nc_spm_08_grass7):~/software/grass72 > gdb r.compress
GNU gdb (GDB) Fedora 8.0-24.fc26
...
(gdb) r -u elev_lid792_1m_viewshed
Starting program: /home/mneteler/software/grass72/dist.x86_64-pc-linux-
gnu/bin/r.compress -u elev_lid792_1m_viewshed
...
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff73b1ddd in __memset_avx2_erms () from /lib64/libc.so.6
Missing separate debuginfos, use: dnf debuginfo-install
zlib-1.2.11-2.fc26.x86_64

(gdb) bt
#0 0x00007ffff73b1ddd in __memset_avx2_erms () from /lib64/libc.so.6
#1 0x00007ffff798da23 in G_zero (buf=0x0, i=6008) at zero.c:25
#2 0x00007ffff7bc2145 in open_raster_new (name=0x606a00
"elev_lid792_1m_viewshed", open_mode=3, map_type=1) at open.c:714
#3 0x00007ffff7bc165b in Rast_open_fp_new_uncompressed (name=0x606a00
"elev_lid792_1m_viewshed") at open.c:507
#4 0x0000000000402327 in doit (name=0x606a00 "elev_lid792_1m_viewshed",
uncompress=1, map_type=1) at main.c:268
#5 0x0000000000401d2c in process (name=0x606a00
"elev_lid792_1m_viewshed", uncompress=1) at main.c:164
#6 0x000000000040198d in main (argc=3, argv=0x7fffffffd488) at main.c:99

(gdb) bt full
#0 0x00007ffff73b1ddd in __memset_avx2_erms () from /lib64/libc.so.6
No symbol table info available.
#1 0x00007ffff798da23 in G_zero (buf=0x0, i=6008) at zero.c:25
No locals.
#2 0x00007ffff7bc2145 in open_raster_new (name=0x606a00
"elev_lid792_1m_viewshed", open_mode=3, map_type=1) at open.c:714
         xname =
"elev_lid792_1m_viewshed\000\035\343\224\367\377\177\000\000\b\354\230\367\377\177\000\000\350\t\272\367\377\177\000\000\020\313\377\377\377\177\000\000n\342\224\367\377\177\000\000\060\313\377\377\377\177\000\000\000\000\000\000\000\000\000\000\020\314\377\377\377\177\000\000\035\343\224\367\377\177\000\000\b\354\230\367\377\177\000\000\000\231\311`\001\000\000\000\240\275\274\367\377\177\000\000
f`", '\000' <repeats 13 times>,
"\017\000\000\000\000\000\000\000\250\350\377\377\377\177\000\000\340P`\000\000\000\000\000\340\314\377\377\377\177\000\000,\n\272\367\377\177\000\000\240\275\274\367\377\177\000\000
f`", '\000' <repeats 13 times>...
         xmapset =
"user1\000\000\000T\377\230\367\377\177\000\000\360\313\377\377\005\000\000\000\000\231\311`\220\021\241]\020\314\377\377\377\177\000\000l\026\225\367\377\177\000\000\220\314\377\377\377\177\000\000
f`\000\000\000\000\000\240\275\274\367\377\177\000\000+\354\230\367\377\177\000\000\060\314\377\377\377\177\000\000g\027\225\367\377\177\000\000
f`\000\000\000\000\000\240\275\274\367\377\177\000\000\320\314\377\377\377\177\000\000\006ĺ\367\377\177\000\000\360``\000\000\000\000\000\000j`\000\000\000\000\000k-@",
'\000' <repeats 13 times>,
"X\314\377\377\377\177\000\000\000\000\000\000\000\000\000\000\300\313\377\377\377\177\000\000,\n\272\367\377\177\000\000\260\314\377\377\377\177\000\000\231"...
         fcb = 0x60e728
         fd = 1
         cell_fd = 5
         tempname = 0x609630
"/home/mneteler/grassdata/nc_spm_08_grass7/user1/.tmp/oboe.mundialis/11666.1"
         map = 0x6088f0 "elev_lid792_1m_viewshed"
         mapset = 0x6095b0 "user1"
         cell_dir = 0x7ffff7bcdadf "fcell"
         nbytes = 4
#3 0x00007ffff7bc165b in Rast_open_fp_new_uncompressed (name=0x606a00
"elev_lid792_1m_viewshed") at open.c:507
No locals.
#4 0x0000000000402327 in doit (name=0x606a00 "elev_lid792_1m_viewshed",
uncompress=1, map_type=1) at main.c:268
         cellhd = {format = -1, compressed = 2, rows = 750, rows3 = 750,
cols = 700, cols3 = 700, depths = 1, proj = 99, zone = 0, ew_res = 1,
           ew_res3 = 1, ns_res = 1, ns_res3 = 1, tb_res = 1, north =
220750, south = 220000, east = 639000, west = 638300, top = 1, bottom = 0}
         new = 4200112
         old = 0
         nrows = 32767
         row = 0
         rast = 0x7ffff7ba0a2c <state+44>
#5 0x0000000000401d2c in process (name=0x606a00
"elev_lid792_1m_viewshed", uncompress=1) at main.c:164
         colr = {version = 0, shift = 0, invert = 0, is_float = 0, null_set
= 0, null_red = 0 '\000', null_grn = 0 '\000', null_blu = 0 '\000',
           undef_set = 0, undef_red = 0 '\000', undef_grn = 0 '\000',
undef_blu = 0 '\000', fixed = {rules = 0x60e4a0, n_rules = 255, lookup = {
               red = 0x0, grn = 0x0, blu = 0x0, set = 0x0, nalloc = 0,
active = 0}, fp_lookup = {vals = 0x0, rules = 0x0, nalloc = 0,
               active = 0}, min = 11.294887542724609, max = 180}, modular =
{rules = 0x0, n_rules = 0, lookup = {red = 0x0, grn = 0x0, blu = 0x0,
               set = 0x0, nalloc = 0, active = 0}, fp_lookup = {vals = 0x0,
rules = 0x0, nalloc = 0, active = 0}, min = 0, max = -1},
           cmin = 11.294887542724609, cmax = 180, organizing = 0}
         hist = {fields = {0x606840 "Fri Jul 29 13:45:27 2016", 0x606de0
"elev_lid792_1m_viewshed", 0x607870 "user1", 0x606aa0 "mneteler",
             0x606ac0 "raster", 0x606ae0 "", 0x606b00 "", 0x606b20
"generated by r.viewshed"}, nlines = 4, lines = 0x606c50}
         cats = {ncats = 0, num = 0, title = 0x608720 "", fmt = 0x608740
"", m1 = 0, a1 = 0, m2 = 0, a2 = 0, q = {truncate_only = 0,
             round_only = 0, defaultDRuleSet = 6316576, defaultCRuleSet =
0, infiniteLeftSet = 0, infiniteRightSet = 0, cRangeSet = 12369,
             maxNofRules = 0, nofRules = 0, defaultDMin =
6.9533486653477228e-310, defaultDMax = 6.9533486653477228e-310,
defaultCMin = 95,
             defaultCMax = 0, infiniteDLeft = 6.9531436082562536e-310,
infiniteDRight = 6.953355807227106e-310, infiniteCLeft = -144561320,
             infiniteCRight = 32767, dMin = -nan(0xf800000003011), dMax =
4.9406564584124654e-324, cMin = 6312160, cMax = 0, table = 0x1,
             fp_lookup = {vals = 0x3100000007, rules = 0x0, nalloc = 0,
active = 0, inf_dmin = 1.040701294729263e+143,
               inf_dmax = 2.6312747812465374e-312, inf_min = 0, inf_max =
0}}, labels = 0x0, marks = 0x40, nalloc = 0, last_marked_rule = -1}
         quant = {truncate_only = 0, round_only = 1, defaultDRuleSet =
-148335230, defaultCRuleSet = 32767, infiniteLeftSet = 0,
           infiniteRightSet = 0, cRangeSet = -144565552, maxNofRules = 0,
nofRules = 0, defaultDMin = 6.2677389677743225e-310,
           defaultDMax = 6.9533558072152484e-310, defaultCMin = 4200112,
defaultCMax = 0, infiniteDLeft = -nan(0xf800000003101),
           infiniteDRight = 4.9703003971629402e-321, infiniteCLeft =
-144565552, infiniteCRight = 32767, dMin = 4.9406564584124654e-324,
           dMax = 1.0397779375927461e-312, cMin = 0, cMax = 0, table = 0x0,
fp_lookup = {vals = 0x0, rules = 0x7c0000005b, nalloc = 119,
             active = 0, inf_dmin = 1.0880979340924386e-306, inf_dmax =
4.9406564584124654e-324, inf_min = 4, inf_max = 49}}
         colr_ok = 0
         hist_ok = 1
         cats_ok = 1
         quant_ok = 1
         newsize = 45
         oldsize = 2106759
         diff = 140737340387566
         map_type = 1
         rname =
"\000\000\000\000\000\000\000\000,\n\272\367\377\177\000\000P\321\377\377\377\177\000\000\231\362\224\367\377\177\000\000p\324\377\377\000\000\000\000\n\004)\367\377\177\000\000
\322\377\377\377\177\000\000\340\321\377\377\377\177\000\000\240\321\377\377\377\177\000\000m*\231\367\377\177\000\000|*\231\367\377\177\000\000&\322\377\377\377\177\000\000\200\322\377\377\377\177\000\000\377%\227\367\377\177\000\000P\322\377\377\000\000\000\000\000\000\000\000\377\177",
'\000' <repeats 18 times>,
"old\000_\000\000\000\060_\231\367\377\177\000\000\000\000\000\000\000\000\000_\200i`\000\000\000\000\000hijklmnopqrstuvwxyz",
'\000' <repeats 13 times>...
         rmapset =
"\000\000\000\000\000\000\000\000\240i`\000\000\000\000\000raster\000\000\000\000\000\000\000\000\000\000\200\322\377\377\003\000\000\000\002+\231\367\377\177\000\000`\016\272\367\377\177",
'\000' <repeats 19 times>, "j`", '\000' <repeats 14 times>,
"\231\311`\220\021\241]`\016\272\367\377\177\000\000\260\026@\000\000\000\000\000\060\323\377\377\377\177\000\000O\376\226\367\377\177\000\000\210\324\377\377\377\177\000\000\005\000\000\000\000\000\000\000\360\321\377\377\377\000\000\000\000\000\000\000<",
'\000' <repeats 11 times>, "p\324\377\377", '\000' <repeats 12 times>,
"Z\331\377\377\377\177\000\000mi`", '\000' <repeats 13 times>...
         mapset = 0x606a60 "user1"
         data_fd = 3
         sizestr = 0x10 <error: Cannot access memory at address 0x10>
#6 0x000000000040198d in main (argc=3, argv=0x7fffffffd478) at main.c:99
         stat = 1
         n = 0
         name = 0x606a00 "elev_lid792_1m_viewshed"
         module = 0x7ffff7ba0e88 <state+40>
         map = 0x7ffff7ba0ee8 <state+136>
         uncompress = 0x7ffff7ba0eb8 <state+88>
         pflag = 0x606890
         gflag = 0x6068e0
(gdb)
}}}

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

#3412: r.compress -u segfault
--------------------------+---------------------------------
  Reporter: neteler | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.2
Component: Default | Version: svn-releasebranch72
Resolution: | Keywords: r.compress
       CPU: Unspecified | Platform: Linux
--------------------------+---------------------------------

Comment (by mmetz):

Replying to [ticket:3412 neteler]:
> When trying to uncompress a map, r.compress segfaults:

Apparently a bug in the rasterlib when NULLs are compressed, but not data.
Should be fixed in r71448,50 (trunk, relbr72).

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

#3412: r.compress -u segfault
--------------------------+---------------------------------
  Reporter: neteler | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.2.2
Component: Default | Version: svn-releasebranch72
Resolution: fixed | Keywords: r.compress
       CPU: Unspecified | Platform: Linux
--------------------------+---------------------------------
Changes (by neteler):

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

Comment:

Thanks for the fix! Closing.

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

#3412: r.compress -u segfault
--------------------------+---------------------------------
  Reporter: neteler | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.2.2
Component: Default | Version: svn-releasebranch72
Resolution: fixed | Keywords: r.compress
       CPU: Unspecified | Platform: Linux
--------------------------+---------------------------------

Comment (by mmetz):

Replying to [comment:2 neteler]:
> Thanks for the fix! Closing.

Note that r.compress -u still compresses null files if
GRASS_COMPRESS_NULLS=1. OK?

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

#3412: r.compress -u segfault
--------------------------+---------------------------------
  Reporter: neteler | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.2.2
Component: Default | Version: svn-releasebranch72
Resolution: fixed | Keywords: r.compress
       CPU: Unspecified | Platform: Linux
--------------------------+---------------------------------

Comment (by neteler):

Replying to [comment:3 mmetz]:
> Note that r.compress -u still compresses null files if
GRASS_COMPRESS_NULLS=1. OK?

You mean that the null files are ignored with -u?

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

#3412: r.compress -u segfault
--------------------------+---------------------------------
  Reporter: neteler | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.2.2
Component: Default | Version: svn-releasebranch72
Resolution: fixed | Keywords: r.compress
       CPU: Unspecified | Platform: Linux
--------------------------+---------------------------------

Comment (by mmetz):

Replying to [comment:4 neteler]:
> Replying to [comment:3 mmetz]:
> > Note that r.compress -u still compresses null files if
GRASS_COMPRESS_NULLS=1. OK?
>
> You mean that the null files are ignored with -u?

Yes, the -u flag does not affect null file compression.

On library level: when opening a new raster with
Rast_open_new_uncompressed(), null files are still compressed if
GRASS_COMPRESS_NULLS=1. Maybe it would be more logical to not compress
null files with Rast_open_new_uncompressed().

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

#3412: r.compress -u segfault
--------------------------+---------------------------------
  Reporter: neteler | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.2.2
Component: Default | Version: svn-releasebranch72
Resolution: fixed | Keywords: r.compress
       CPU: Unspecified | Platform: Linux
--------------------------+---------------------------------

Comment (by neteler):

Replying to [comment:5 mmetz]:
> On library level: when opening a new raster with
Rast_open_new_uncompressed(), null files are still compressed if
GRASS_COMPRESS_NULLS=1. Maybe it would be more logical to not compress
null files with Rast_open_new_uncompressed().

From a user's point of view it would be beautiful to have the null file
un/compression done according to the use of r.compress with/-out -u.
Probably for 7.4?

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