Opened 15 years ago

Closed 15 years ago

#814 closed defect (invalid)

r.resamp.stats memory corruption when resampling from different projection/zone

Reported by: pertusus Owned by: grass-dev@…
Priority: normal Milestone: 6.4.0
Component: Raster Version: 6.4.0 RCs
Keywords: Cc:
CPU: x86-32 Platform: Linux

Description

I would like to resample a map from a mapset to another that have a different region using r.resamp.stats -w

In the new mapset, CRU_GRID, region is:

 > g.region -p
projection: 3 (Latitude-Longitude)
zone:       0
datum:      ** unknown (default: WGS84) **
ellipsoid:  sphere
north:      90N
south:      90S
west:       180W
east:       180E
nsres:      0:30
ewres:      0:30
rows:       360
cols:       720
cells:      259200

In the PERMANENT mapset, the region is:

 > g.region -p
projection: 99 (Lambert Azimuthal Equal Area)
zone:       0
datum:      ** unknown (default: WGS84) **
ellipsoid:  sphere
north:      4149500
south:      -5044500
west:       -4368500
east:       4367500
nsres:      1000
ewres:      1000
rows:       9194
cols:       8736
cells:      80318784

The map is a normal raster map in the PERMANENT mapset:

 > r.info one_up_basin_194
 +----------------------------------------------------------------------------+
 | Layer:    one_up_basin_194               Date: Wed Nov 18 18:41:41 2009    |
 | Mapset:   PERMANENT                      Login of Creator: dumas           |
 | Location: network_af                                                       |
 | DataBase: /home/dumas/maps                                                 |
 | Title:     ( one_up_basin_194 )                                            |
 | Timestamp: none                                                            |
 |----------------------------------------------------------------------------|
 |                                                                            |
 |   Type of Map:  raster               Number of Categories: 1               |
 |   Data Type:    CELL                                                       |
 |   Rows:         3996                                                       |
 |   Columns:      1830                                                       |
 |   Total Cells:  7312680                                                    |
 |        Projection: Lambert Azimuthal Equal Area                            |
 |            N:    2969500    S:   -1026500   Res:  1000                     |
 |            E:    2189500    W:     359500   Res:  1000                     |
 |   Range of data:    min = 1  max = 1                                       |
 |                                                                            |
 |   Data Description:                                                        |
 |    generated by r.mapcalc                                                  |
 |                                                                            |
 |   Comments:                                                                |
 |    if(isnull(up_basin_194), 1 / 0, 1)                                      |
 |                                                                            |
 +----------------------------------------------------------------------------+
 > r.stats -c one_up_basin_194
 100%
1 866152
* 79452632

When in the CRU_GRID mapset I try to resample the map from the PERMANENT mapset, I get an error message, and glibc detects some memory corruption:

 > r.resamp.stats -w input=one_up_basin_194@PERMANENT  output=one_up_basin_194
WARNING: G_set_window(): projection/zone differs from that of currently
         open raster maps
*** glibc detected *** r.resamp.stats: malloc(): memory corruption (fast): 0x081725f8 ***
======= Backtrace: =========
/lib/libc.so.6[0x658ba9]
/lib/libc.so.6(__libc_malloc+0x67)[0x659d87]
/usr/lib/libgrass_gis.so.6.4(G__malloc+0x2a)[0xeca82a]
/usr/lib/libgrass_gis.so.6.4(G__location_path+0x5c)[0xee416c]
/usr/lib/libgrass_gis.so.6.4(G__file_name+0x3f)[0xed936f]
/usr/lib/libgrass_gis.so.6.4[0xed99f2]
/usr/lib/libgrass_gis.so.6.4[0xed9aca]
/usr/lib/libgrass_gis.so.6.4(G_find_cell+0x2e)[0xed954e]
/usr/lib/libgrass_gis.so.6.4(G__check_for_auto_masking+0x4b)[0xecc72b]
/usr/lib/libgrass_gis.so.6.4(G_set_window+0x164)[0xefae44]
r.resamp.stats(main+0x10c3)[0x804a453]
/lib/libc.so.6(__libc_start_main+0xdc)[0x603e9c]
r.resamp.stats(w_var+0xa5)[0x80492d1]
======= Memory map: ========
00176000-00177000 r-xp 00176000 00:00 0          [vdso]
0019b000-0019f000 r-xp 00000000 08:01 1368258    /usr/lib/libgrass_stats.so.6.4.0RC5
0019f000-001a0000 rwxp 00003000 08:01 1368258    /usr/lib/libgrass_stats.so.6.4.0RC5
003b1000-003cb000 r-xp 00000000 08:01 834029     /lib/ld-2.5.so
003cb000-003cc000 r-xp 00019000 08:01 834029     /lib/ld-2.5.so
003cc000-003cd000 rwxp 0001a000 08:01 834029     /lib/ld-2.5.so
00539000-0054b000 r-xp 00000000 08:01 1367055    /usr/lib/libz.so.1.2.3
0054b000-0054c000 rwxp 00011000 08:01 1367055    /usr/lib/libz.so.1.2.3
005ee000-0072d000 r-xp 00000000 08:01 834042     /lib/libc-2.5.so
0072d000-0072f000 r-xp 0013f000 08:01 834042     /lib/libc-2.5.so
0072f000-00730000 rwxp 00141000 08:01 834042     /lib/libc-2.5.so
00730000-00733000 rwxp 00730000 00:00 0 
0077a000-00782000 r-xp 00000000 08:01 1366008    /usr/lib/libgrass_datetime.so.6.4.0RC5
00782000-00783000 rwxp 00007000 08:01 1366008    /usr/lib/libgrass_datetime.so.6.4.0RC5
009f0000-009fb000 r-xp 00000000 08:01 833980     /lib/libgcc_s-4.1.2-20080825.so.1
009fb000-009fc000 rwxp 0000a000 08:01 833980     /lib/libgcc_s-4.1.2-20080825.so.1
00b4e000-00b73000 r-xp 00000000 08:01 834068     /lib/libm-2.5.so
00b73000-00b74000 r-xp 00024000 08:01 834068     /lib/libm-2.5.so
00b74000-00b75000 rwxp 00025000 08:01 834068     /lib/libm-2.5.so
00ebd000-00f10000 r-xp 00000000 08:01 1367259    /usr/lib/libgrass_gis.so.6.4.0RC5
00f10000-00f11000 rwxp 00053000 08:01 1367259    /usr/lib/libgrass_gis.so.6.4.0RC5
00f11000-00f18000 rwxp 00f11000 00:00 0 
00f5f000-00f61000 r-xp 00000000 08:01 834062     /lib/libdl-2.5.so
00f61000-00f62000 r-xp 00001000 08:01 834062     /lib/libdl-2.5.so
00f62000-00f63000 rwxp 00002000 08:01 834062     /lib/libdl-2.5.so
08048000-0804b000 r-xp 00000000 08:01 182315     /usr/lib/grass-6.4.0RC5/bin/r.resamp.stats
0804b000-0804c000 rw-p 00002000 08:01 182315     /usr/lib/grass-6.4.0RC5/bin/r.resamp.stats
08170000-08191000 rw-p 08170000 00:00 0          [heap]
b7c00000-b7c21000 rw-p b7c00000 00:00 0 
b7c21000-b7d00000 ---p b7c21000 00:00 0 
b7d2c000-b7f2c000 r--p 00000000 08:01 1373566    /usr/lib/locale/locale-archive
b7f2c000-b7f2e000 rw-p b7f2c000 00:00 0 
b7f43000-b7f44000 r--p 02b73000 08:01 1373566    /usr/lib/locale/locale-archive
b7f44000-b7f45000 rw-p b7f44000 00:00 0 
bfa49000-bfa5e000 rw-p bffea000 00:00 0          [stack]
Abandon

Change History (3)

in reply to:  description ; comment:1 by glynn, 15 years ago

Replying to pertusus:

I would like to resample a map from a mapset to another that have a different region using r.resamp.stats -w

In the new mapset, CRU_GRID, region is:

 > g.region -p
projection: 3 (Latitude-Longitude)

In the PERMANENT mapset, the region is:

 > g.region -p
projection: 99 (Lambert Azimuthal Equal Area)

Whoa. This shouldn't be possible. Projections are per-location, not per-mapset. I suggest running

g.region -d

in both mapsets, then trying again.

I'm curious as to how you ended up with a WIND file with a different projection than the DEFAULT_WIND file. If it's because you copied a mapset directory from one location to another, the answer is "don't do that".

in reply to:  1 ; comment:2 by pertusus, 15 years ago

Replying to glynn:

Whoa. This shouldn't be possible. Projections are per-location, not per-mapset. I suggest running

g.region -d

in both mapsets, then trying again.

Ok, I indeed did wrong. After g.region -d in CRU_GRID the region from the PERMANENT is reused in the mapset and indeed it works (but does nothing, and certainly doesn't do what I want to...).

I'm curious as to how you ended up with a WIND file with a different projection than the DEFAULT_WIND file. If it's because you copied a mapset directory from one location to another, the answer is "don't do that".

I do this all the time to start a new location, I didn't find another way to do it not manually (I have a location with only PERMANENT with only DEFAULT_WIND PROJ_INFO PROJ_UNITS WIND and I copy it). And I also did it in that case, I took those files from a different location and put them in the mapset... I found it a bit cumbersome, but I thought that it was the only way to be able to do what I want to. Looks like I was wrong, if mapsets have to share a projection, then, indeed, I am still missing something. Back to the documentation, I guess.

In any case the memory corruption is certainly something to fix.

in reply to:  2 comment:3 by glynn, 15 years ago

Resolution: invalid
Status: newclosed

Replying to pertusus:

In any case the memory corruption is certainly something to fix.

Not really. Modifying the code to detect and handle situations where the user has manually corrupted the database would take far more effort than we can spare, would make the code harder to understand, and would negatively affect performance.

Note: See TracTickets for help on using tickets.