the problematic  test is:
    slurp("./t")

Unix accepts to open a directory but that leads to problem down the pipe.

This following patch, apparently innocent, should fix the problem by refusing 
to open a 
directory but it triggers a memory bug.

../../parrot ../../runtime/parrot/library/PGE/Perl6Grammar.pir  --
output=PGE/builtins_gen.pir PGE/builtins.pg
parrot(14927) malloc: *** mmap(size=1920102400) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Parrot VM: PANIC: Out of mem!
C file src/gc/memory.c, line 51

Thread 0 Crashed:
0   libSystem.B.dylib                   0x9589fb9e __kill + 10
1   libSystem.B.dylib                   0x95916ec2 raise + 26
2   libparrot.dylib                     0x00526f7e do_panic + 606 
(exceptions.c:628)
3   libparrot.dylib                     0x0052e159 mem_sys_allocate + 73 
(memory.c:52)
4   libparrot.dylib                     0x004befa4 string_to_cstring + 68 
(string.c:2108)
5   libparrot.dylib                     0x005772db Parrot_stat_info_intval + 27 
(stat.c:160)
6   libparrot.dylib                     0x005fbe29 PIO_unix_open + 121 
(io_unix.c:306)
7   libparrot.dylib                     0x005fda4b PIO_open_down + 59 
(io_passdown.c:49)
8   libparrot.dylib                     0x005fa46f PIO_buf_open + 47 
(io_buf.c:208)
9   libparrot.dylib                     0x005fda4b PIO_open_down + 59 
(io_passdown.c:49)
10  libparrot.dylib                     0x005f97b6 PIO_open + 70 (io.c:721)
11  libparrot.dylib                     0x004cd06d Parrot_open_p_s_sc + 125 
(io.ops:146)
12  libparrot.dylib                     0x0057af97 runops_slow_core + 183 
(runops_cores.c:222)
13  libparrot.dylib                     0x0053a12f runops_int + 447 
(interpreter.c:942)
14  libparrot.dylib                     0x0053aab2 runops + 194 
(inter_run.c:105)
15  libparrot.dylib                     0x0053ad54 runops_args + 436 
(inter_run.c:237)
16  libparrot.dylib                     0x0053b0ea Parrot_run_meth_fromc_args + 
58 
(inter_run.c:426)
17  libparrot.dylib                     0x00682fe1 initialize_parents + 321 
(class.pmc:329)
18  libparrot.dylib                     0x00684efc Parrot_Class_instantiate + 
1260 
(class.pmc:1129)
19  libparrot.dylib                     0x004dad11 Parrot_new_p_p + 129 
(pmc.ops:120)
20  libparrot.dylib                     0x0057af97 runops_slow_core + 183 
(runops_cores.c:222)
21  libparrot.dylib                     0x0053a12f runops_int + 447 
(interpreter.c:942)
22  libparrot.dylib                     0x0053aab2 runops + 194 
(inter_run.c:105)
23  libparrot.dylib                     0x0053ad54 runops_args + 436 
(inter_run.c:237)
24  libparrot.dylib                     0x0053ae89 Parrot_runops_fromc_args + 
73 
(inter_run.c:300)
25  libparrot.dylib                     0x00570490 run_sub + 112 
(packfile.c:496)
26  libparrot.dylib                     0x005705fe do_1_sub_pragma + 334 
(packfile.c:557)
27  libparrot.dylib                     0x00570961 do_sub_pragmas + 289 
(packfile.c:722)
28  libparrot.dylib                     0x00574cfe PackFile_append_pbc + 110 
(packfile.c:3723)
29  libparrot.dylib                     0x00574ea8 Parrot_load_bytecode + 408 
(packfile.c:3778)
30  libparrot.dylib                     0x004c0710 Parrot_load_bytecode_sc + 48 
(core.ops:153)
31  libparrot.dylib                     0x0057af97 runops_slow_core + 183 
(runops_cores.c:222)
32  libparrot.dylib                     0x0053a12f runops_int + 447 
(interpreter.c:942)
33  libparrot.dylib                     0x0053aab2 runops + 194 
(inter_run.c:105)
34  libparrot.dylib                     0x0053ad54 runops_args + 436 
(inter_run.c:237)
35  libparrot.dylib                     0x0053ae89 Parrot_runops_fromc_args + 
73 
(inter_run.c:300)
36  libparrot.dylib                     0x00570490 run_sub + 112 
(packfile.c:496)
37  libparrot.dylib                     0x005706e5 do_1_sub_pragma + 565 
(packfile.c:589)
38  libparrot.dylib                     0x00570961 do_sub_pragmas + 289 
(packfile.c:722)
39  libparrot.dylib                     0x00574f99 PackFile_fixup_subs + 41 
(packfile.c:3816)
40  libparrot.dylib                     0x006fb4d0 imcc_run_pbc + 240 
(main.c:791)
41  libparrot.dylib                     0x006fbf8d imcc_run + 861 (main.c:1081)
42  parrot                              0x00001f79 main + 185 (main.c:61)
43  parrot                              0x00001e86 start + 54

Thread 0 crashed with X86 Thread State (32-bit):
  eax: 0x00000000  ebx: 0x00526d2c  ecx: 0xbfffe7fc  edx: 0x9589fb9e
  edi: 0x0071e330  esi: 0x00000000  ebp: 0xbfffe818  esp: 0xbfffe7fc
   ss: 0x0000001f  efl: 0x00000286  eip: 0x9589fb9e   cs: 0x00000007
   ds: 0x0000001f   es: 0x0000001f   fs: 0x00000000   gs: 0x00000037
  cr2: 0xffe17884


--- ./src/io/io_unix.c.orig     2008-09-19 17:56:19.000000000 +0200
+++ ./src/io/io_unix.c  2008-09-19 18:03:44.000000000 +0200
@@ -303,6 +303,11 @@
     if ((flags & (PIO_F_WRITE | PIO_F_READ)) == 0)
         return NULL;
 
+    if (Parrot_stat_info_intval(interp, spath, STAT_ISDIR)) {
+        errno = EISDIR;
+        return NULL;
+    }
+
     oflags = flags_to_unix(flags);
 
     /* Only files for now */

Reply via email to