Code to generate a large file that will segfault std.algorithm.splitter.
text/plain
1489
Comments
Comment #0 by sprw121 — 2015-05-29T06:30:46Z
Created attachment 1524
Code to generate a large file that will segfault std.algorithm.splitter.
I discovered that std.algorithm's splitter function segfaults when called over casted memory mapped filed.
Interestingly I found this when reenabling the GC on an application we've been running for a long time with GC.disable(). The bug does not occur with GC.disable, but with GC enabled it segfaults everytime.
Linked is a test program that segfaults when run in a Ubuntu 12.04 VM on a mid-2014 MBR.
Seems transient when compiled with -g flag. Seems to only segfault on large files.
http://dpaste.dzfl.pl/96e898051fb2
Backtrace from core dump:
#0 memchr () at ../sysdeps/x86_64/memchr.S:59
#1 0x000000000045dc0f in std.algorithm.searching.__T4findVAyaa6_61203d3d2062TAyaTaZ.find() ()
#2 0x000000000045db86 in std.algorithm.searching.__T4findVAyaa6_61203d3d2062TAyaTaZ.find() ()
#3 0x000000000045d051 in std.algorithm.iteration.__T8splitterVAyaa6_61203d3d2062TAyaTaZ.splitter() ()
#4 0x000000000045a622 in gen_map.file_to_map() ()
#5 0x000000000045a7b3 in D main ()
#6 0x0000000000463abb in rt.dmain2._d_run_main() ()
#7 0x0000000000463a0e in rt.dmain2._d_run_main() ()
#8 0x0000000000463a74 in rt.dmain2._d_run_main() ()
#9 0x0000000000463a0e in rt.dmain2._d_run_main() ()
#10 0x0000000000463988 in _d_run_main ()
#11 0x000000000045f38f in main ()
Comment #1 by boris2.9 — 2019-12-09T23:22:55Z
The problem is that MmFile is a class and the construct "cast(string)mapFile[]" doesn't prevent the object from being collected.
Declaring the variable with scope
scope mapFile = new MmFile(map_path);
or simply using it after the loop
foreach(line ; splitter(cast(string)mapFile[], '\n'))
{
...
}
mapFile.length;
makes the program succeed.