Description
I’m seeing nondeterministic heap corruption (e.g. corrupt size vs prev_size) when pysurf reads unstructured CGNS files. The crash shows up around the second zone iteration (often on deallocate), but the root cause appears to be earlier memory corruption in the connectivity read.
cg_elements_read_f seems to expect an integer(cgsize_t) buffer, but pySurf passes zones(iZone)%sections(sec)%elemConn (declared as integer(intType)) directly. When cgsize_t is 64-bit and intType is 32-bit, CGNS writes past the buffer / corrupts the heap.
|
zones(iZone)%sections(sec)%elemConn, CG_Null, ierr) |
Workaround / Fix
Reading element connectivity into a temporary cgsize_t array and then assigning fixes it:
integer(kind=cgsize_t), allocatable :: elements(:)
if (allocated(elements)) deallocate(elements)
allocate(elements(nConn*nElem))
call cg_elements_read_f(cg, base, iZone, sec, elements, CG_Null, ierr)
if (ierr .eq. CG_ERROR) call cg_error_exit_f
zones(iZone)%sections(sec)%elemConn = int(elements, kind=intType) + zoneStart
(Original code passed zones(iZone)%sections(sec)%elemConn directly to cg_elements_read_f.)
Suggestion
Either store elemConn as cgsize_t internally, or always read into a cgsize_t temporary and convert to intType afterward.
Description
I’m seeing nondeterministic heap corruption (e.g.
corrupt size vs prev_size) when pysurf reads unstructured CGNS files. The crash shows up around the second zone iteration (often ondeallocate), but the root cause appears to be earlier memory corruption in the connectivity read.cg_elements_read_fseems to expect aninteger(cgsize_t)buffer, but pySurf passeszones(iZone)%sections(sec)%elemConn(declared asinteger(intType)) directly. Whencgsize_tis 64-bit andintTypeis 32-bit, CGNS writes past the buffer / corrupts the heap.pysurf/src/CGNSInterface/cgnsInterface.F90
Line 467 in d36efa4
Workaround / Fix
Reading element connectivity into a temporary
cgsize_tarray and then assigning fixes it:(Original code passed
zones(iZone)%sections(sec)%elemConndirectly tocg_elements_read_f.)Suggestion
Either store
elemConnascgsize_tinternally, or always read into acgsize_ttemporary and convert tointTypeafterward.