This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libfortran/25142] New: Segfault in unformatted_write for large records

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
     &     recl=28000)
      write(3,rec=1) s
>gfortran junk2.f
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]