I get a segmentation fault when trying to execute the 
following simple program:
>cat junk2.f
      program junk
      character*28000 s
      do i=1,28000
        s(i:i) = 'a'
      end do
      open(3,file='junk_file',form='unformatted',access='direct',
     &     recl=28000)
      write(3,rec=1) s
      end
>gfortran junk2.f
>./a.out
Segmentation fault

I think, the problem can be traced back to mmap_alloc(), 
where the size of the allocated memory is calculated as 

length = ((where - offset) & page_mask) + 2 * page_size;

and turns out to be 8192 bytes on my system, with no checks 
being made to see if this is large enough for the actual 
data size. The subsequent memcpy in unformatted_write leads 
to segmentation fault. 

The fix is trivial (allocate enough memroy in mmap_alloc), 
unless there are considerations concerning the maximum 
memory use of the runtime library.


-- 
           Summary: Segfault in unformatted_write for large records
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: iwan at irs dot phy dot nrc dot ca
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25142

Reply via email to