Issue #3 new

Not calling copy_stat on new entry segfaults Ruby

Romulo Ceccon
created an issue

The following example with libarchive 0.1.2 segfaults Ruby on my machine:

require 'libarchive'

Archive.write_open_filename('a.zip', Archive::COMPRESSION_NONE, Archive::FORMAT_ZIP) do |ar|
  ar.new_entry do |entry|
    entry.pathname = 'a.txt'
    ar.write_header(entry)
    ar.write_data('this is going to segfault ruby')
  end
end

Tested with rubies:

  • ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]
  • ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-linux]
  • ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
bug.rb:3: [BUG] Segmentation fault
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0003 p:---- s:0010 e:000009 CFUNC  :write_open_filename
c:0002 p:0039 s:0004 E:001ac8 EVAL   bug.rb:3 [FINISH]
c:0001 p:0000 s:0002 E:001288 TOP    [FINISH]

bug.rb:3:in `<main>'
bug.rb:3:in `write_open_filename'

-- C level backtrace information -------------------------------------------
ruby(+0x179c68) [0x7f5a06218c68]
ruby(+0x1e708a) [0x7f5a0628608a]
ruby(rb_bug+0xb3) [0x7f5a06287303]
ruby(+0xf2356) [0x7f5a06191356]
/lib/x86_64-linux-gnu/libpthread.so.0(+0xfbb0) [0x7f5a05c6cbb0] ../nptl/sysdeps/pthread/funlockfile.c:29
/usr/lib/x86_64-linux-gnu/libarchive.so.13(+0x799b6) [0x7f5a044469b6] fileops.c:1188
/usr/lib/x86_64-linux-gnu/libarchive.so.13(+0x54569) [0x7f5a04421569] vfscanf.c:2935
/home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/libarchive-0.1.2/lib/rblibarchive.so(+0x9c47) [0x7f5a04677c47] pthread_getattr_np.c:193
ruby(+0x163724) [0x7f5a06202724]
ruby(+0x170c4e) [0x7f5a0620fc4e]
ruby(+0x16806e) [0x7f5a0620706e]
ruby(+0x16b91a) [0x7f5a0620a91a]
ruby(rb_iseq_eval_main+0x204) [0x7f5a06216ab4]
ruby(+0x21cea) [0x7f5a060c0cea]
ruby(ruby_run_node+0x2d) [0x7f5a060c4bcd]
ruby(+0x217bb) [0x7f5a060c07bb]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f5a04f6dde5] libc-start.c:260
ruby(+0x217e9) [0x7f5a060c07e9]

-- Other runtime information -----------------------------------------------

* Loaded script: bug.rb

* Loaded features:

    0 enumerator.so
    1 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/2.0.0/x86_64-linux/enc/encdb.so
    2 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/2.0.0/x86_64-linux/enc/trans/transdb.so
    3 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/2.0.0/x86_64-linux/rbconfig.rb
    4 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/compatibility.rb
    5 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/defaults.rb
    6 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/deprecate.rb
    7 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/errors.rb
    8 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/version.rb
    9 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/requirement.rb
   10 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/platform.rb
   11 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/basic_specification.rb
   12 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/stub_specification.rb
   13 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb
   14 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/exceptions.rb
   15 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_gem.rb
   16 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/2.0.0/thread.rb
   17 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb
   18 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb
   19 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems.rb
   20 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/path_support.rb
   21 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/dependency.rb
   22 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/libarchive-0.1.2/lib/rblibarchive.so
   23 /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/libarchive-0.1.2/lib/libarchive.rb

* Process memory map:

7f5a031b1000-7f5a031c6000 r-xp 00000000 08:01 2097363                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f5a031c6000-7f5a033c5000 ---p 00015000 08:01 2097363                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f5a033c5000-7f5a033c6000 r--p 00014000 08:01 2097363                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f5a033c6000-7f5a033c7000 rw-p 00015000 08:01 2097363                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f5a033c7000-7f5a03523000 r-xp 00000000 08:01 10749299                   /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.1
7f5a03523000-7f5a03722000 ---p 0015c000 08:01 10749299                   /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.1
7f5a03722000-7f5a0372a000 r--p 0015b000 08:01 10749299                   /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.1
7f5a0372a000-7f5a0372c000 rw-p 00163000 08:01 10749299                   /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.1
7f5a0372c000-7f5a0372d000 rw-p 00000000 00:00 0 
7f5a0372d000-7f5a03745000 r-xp 00000000 08:01 2097680                    /lib/x86_64-linux-gnu/libz.so.1.2.8
7f5a03745000-7f5a03944000 ---p 00018000 08:01 2097680                    /lib/x86_64-linux-gnu/libz.so.1.2.8
7f5a03944000-7f5a03945000 r--p 00017000 08:01 2097680                    /lib/x86_64-linux-gnu/libz.so.1.2.8
7f5a03945000-7f5a03946000 rw-p 00018000 08:01 2097680                    /lib/x86_64-linux-gnu/libz.so.1.2.8
7f5a03946000-7f5a03955000 r-xp 00000000 08:01 2097425                    /lib/x86_64-linux-gnu/libbz2.so.1.0.4
7f5a03955000-7f5a03b54000 ---p 0000f000 08:01 2097425                    /lib/x86_64-linux-gnu/libbz2.so.1.0.4
7f5a03b54000-7f5a03b55000 r--p 0000e000 08:01 2097425                    /lib/x86_64-linux-gnu/libbz2.so.1.0.4
7f5a03b55000-7f5a03b56000 rw-p 0000f000 08:01 2097425                    /lib/x86_64-linux-gnu/libbz2.so.1.0.4
7f5a03b56000-7f5a03b77000 r-xp 00000000 08:01 2097670                    /lib/x86_64-linux-gnu/liblzma.so.5.0.0
7f5a03b77000-7f5a03d76000 ---p 00021000 08:01 2097670                    /lib/x86_64-linux-gnu/liblzma.so.5.0.0
7f5a03d76000-7f5a03d77000 r--p 00020000 08:01 2097670                    /lib/x86_64-linux-gnu/liblzma.so.5.0.0
7f5a03d77000-7f5a03d78000 rw-p 00021000 08:01 2097670                    /lib/x86_64-linux-gnu/liblzma.so.5.0.0
7f5a03d78000-7f5a03d98000 r-xp 00000000 08:01 2097206                    /lib/x86_64-linux-gnu/liblzo2.so.2.0.0
7f5a03d98000-7f5a03f97000 ---p 00020000 08:01 2097206                    /lib/x86_64-linux-gnu/liblzo2.so.2.0.0
7f5a03f97000-7f5a03f98000 r--p 0001f000 08:01 2097206                    /lib/x86_64-linux-gnu/liblzo2.so.2.0.0
7f5a03f98000-7f5a03f99000 rw-p 00020000 08:01 2097206                    /lib/x86_64-linux-gnu/liblzo2.so.2.0.0
7f5a03f99000-7f5a03f9d000 r-xp 00000000 08:01 2097728                    /lib/x86_64-linux-gnu/libattr.so.1.1.0
7f5a03f9d000-7f5a0419c000 ---p 00004000 08:01 2097728                    /lib/x86_64-linux-gnu/libattr.so.1.1.0
7f5a0419c000-7f5a0419d000 r--p 00003000 08:01 2097728                    /lib/x86_64-linux-gnu/libattr.so.1.1.0
7f5a0419d000-7f5a0419e000 rw-p 00004000 08:01 2097728                    /lib/x86_64-linux-gnu/libattr.so.1.1.0
7f5a0419e000-7f5a041cc000 r-xp 00000000 08:01 10749020                   /usr/lib/x86_64-linux-gnu/libnettle.so.4.7
7f5a041cc000-7f5a043cb000 ---p 0002e000 08:01 10749020                   /usr/lib/x86_64-linux-gnu/libnettle.so.4.7
7f5a043cb000-7f5a043cc000 r--p 0002d000 08:01 10749020                   /usr/lib/x86_64-linux-gnu/libnettle.so.4.7
7f5a043cc000-7f5a043cd000 rw-p 0002e000 08:01 10749020                   /usr/lib/x86_64-linux-gnu/libnettle.so.4.7
7f5a043cd000-7f5a0446a000 r-xp 00000000 08:01 10759525                   /usr/lib/x86_64-linux-gnu/libarchive.so.13.1.2
7f5a0446a000-7f5a0466a000 ---p 0009d000 08:01 10759525                   /usr/lib/x86_64-linux-gnu/libarchive.so.13.1.2
7f5a0466a000-7f5a0466c000 r--p 0009d000 08:01 10759525                   /usr/lib/x86_64-linux-gnu/libarchive.so.13.1.2
7f5a0466c000-7f5a0466d000 rw-p 0009f000 08:01 10759525                   /usr/lib/x86_64-linux-gnu/libarchive.so.13.1.2
7f5a0466d000-7f5a0466e000 rw-p 00000000 00:00 0 
7f5a0466e000-7f5a0467b000 r-xp 00000000 08:01 16646268                   /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/libarchive-0.1.2/lib/rblibarchive.so
7f5a0467b000-7f5a0487a000 ---p 0000d000 08:01 16646268                   /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/libarchive-0.1.2/lib/rblibarchive.so
7f5a0487a000-7f5a0487b000 r--p 0000c000 08:01 16646268                   /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/libarchive-0.1.2/lib/rblibarchive.so
7f5a0487b000-7f5a0487c000 rw-p 0000d000 08:01 16646268                   /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/libarchive-0.1.2/lib/rblibarchive.so
7f5a0487c000-7f5a0487e000 r-xp 00000000 08:01 16260883                   /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/2.0.0/x86_64-linux/enc/trans/transdb.so
7f5a0487e000-7f5a04a7e000 ---p 00002000 08:01 16260883                   /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/2.0.0/x86_64-linux/enc/trans/transdb.so
7f5a04a7e000-7f5a04a7f000 r--p 00002000 08:01 16260883                   /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/2.0.0/x86_64-linux/enc/trans/transdb.so
7f5a04a7f000-7f5a04a80000 rw-p 00003000 08:01 16260883                   /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/2.0.0/x86_64-linux/enc/trans/transdb.so
7f5a04a80000-7f5a04a82000 r-xp 00000000 08:01 16260869                   /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/2.0.0/x86_64-linux/enc/encdb.so
7f5a04a82000-7f5a04c81000 ---p 00002000 08:01 16260869                   /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/2.0.0/x86_64-linux/enc/encdb.so
7f5a04c81000-7f5a04c82000 r--p 00001000 08:01 16260869                   /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/2.0.0/x86_64-linux/enc/encdb.so
7f5a04c82000-7f5a04c83000 rw-p 00002000 08:01 16260869                   /home/romulo/ruby/ruby-2.0.0-p353/lib/ruby/2.0.0/x86_64-linux/enc/encdb.so
7f5a04c83000-7f5a04f4c000 r--p 00000000 08:01 10749147                   /usr/lib/locale/locale-archive
7f5a04f4c000-7f5a05109000 r-xp 00000000 08:01 2104810                    /lib/x86_64-linux-gnu/libc-2.17.so
7f5a05109000-7f5a05309000 ---p 001bd000 08:01 2104810                    /lib/x86_64-linux-gnu/libc-2.17.so
7f5a05309000-7f5a0530d000 r--p 001bd000 08:01 2104810                    /lib/x86_64-linux-gnu/libc-2.17.so
7f5a0530d000-7f5a0530f000 rw-p 001c1000 08:01 2104810                    /lib/x86_64-linux-gnu/libc-2.17.so
7f5a0530f000-7f5a05314000 rw-p 00000000 00:00 0 
7f5a05314000-7f5a05417000 r-xp 00000000 08:01 2097757                    /lib/x86_64-linux-gnu/libm-2.17.so
7f5a05417000-7f5a05616000 ---p 00103000 08:01 2097757                    /lib/x86_64-linux-gnu/libm-2.17.so
7f5a05616000-7f5a05617000 r--p 00102000 08:01 2097757                    /lib/x86_64-linux-gnu/libm-2.17.so
7f5a05617000-7f5a05618000 rw-p 00103000 08:01 2097757                    /lib/x86_64-linux-gnu/libm-2.17.so
7f5a05618000-7f5a05622000 r-xp 00000000 08:01 2104809                    /lib/x86_64-linux-gnu/libcrypt-2.17.so
7f5a05622000-7f5a05821000 ---p 0000a000 08:01 2104809                    /lib/x86_64-linux-gnu/libcrypt-2.17.so
7f5a05821000-7f5a05822000 r--p 00009000 08:01 2104809                    /lib/x86_64-linux-gnu/libcrypt-2.17.so
7f5a05822000-7f5a05823000 rw-p 0000a000 08:01 2104809                    /lib/x86_64-linux-gnu/libcrypt-2.17.so
7f5a05823000-7f5a05851000 rw-p 00000000 00:00 0 
7f5a05851000-7f5a05854000 r-xp 00000000 08:01 2104811                    /lib/x86_64-linux-gnu/libdl-2.17.so
7f5a05854000-7f5a05a53000 ---p 00003000 08:01 2104811                    /lib/x86_64-linux-gnu/libdl-2.17.so
7f5a05a53000-7f5a05a54000 r--p 00002000 08:01 2104811                    /lib/x86_64-linux-gnu/libdl-2.17.so
7f5a05a54000-7f5a05a55000 rw-p 00003000 08:01 2104811                    /lib/x86_64-linux-gnu/libdl-2.17.so
7f5a05a55000-7f5a05a5c000 r-xp 00000000 08:01 2104805                    /lib/x86_64-linux-gnu/librt-2.17.so
7f5a05a5c000-7f5a05c5b000 ---p 00007000 08:01 2104805                    /lib/x86_64-linux-gnu/librt-2.17.so
7f5a05c5b000-7f5a05c5c000 r--p 00006000 08:01 2104805                    /lib/x86_64-linux-gnu/librt-2.17.so
7f5a05c5c000-7f5a05c5d000 rw-p 00007000 08:01 2104805                    /lib/x86_64-linux-gnu/librt-2.17.so
7f5a05c5d000-7f5a05c74000 r-xp 00000000 08:01 2104812                    /lib/x86_64-linux-gnu/libpthread-2.17.so
7f5a05c74000-7f5a05e74000 ---p 00017000 08:01 2104812                    /lib/x86_64-linux-gnu/libpthread-2.17.so
7f5a05e74000-7f5a05e75000 r--p 00017000 08:01 2104812                    /lib/x86_64-linux-gnu/libpthread-2.17.so
7f5a05e75000-7f5a05e76000 rw-p 00018000 08:01 2104812                    /lib/x86_64-linux-gnu/libpthread-2.17.so
7f5a05e76000-7f5a05e7a000 rw-p 00000000 00:00 0 
7f5a05e7a000-7f5a05e9d000 r-xp 00000000 08:01 2097760                    /lib/x86_64-linux-gnu/ld-2.17.so
7f5a05f73000-7f5a06079000 rw-p 00000000 00:00 0 
7f5a06095000-7f5a06096000 rw-p 00000000 00:00 0 
7f5a06096000-7f5a06097000 ---p 00000000 00:00 0 
7f5a06097000-7f5a0609c000 rw-p 00000000 00:00 0                          [stack:11342]
7f5a0609c000-7f5a0609d000 r--p 00022000 08:01 2097760                    /lib/x86_64-linux-gnu/ld-2.17.so
7f5a0609d000-7f5a0609f000 rw-p 00023000 08:01 2097760                    /lib/x86_64-linux-gnu/ld-2.17.so
7f5a0609f000-7f5a0634b000 r-xp 00000000 08:01 14287432                   /home/romulo/ruby/ruby-2.0.0-p353/bin/ruby
7f5a0654a000-7f5a0654f000 r--p 002ab000 08:01 14287432                   /home/romulo/ruby/ruby-2.0.0-p353/bin/ruby
7f5a0654f000-7f5a06551000 rw-p 002b0000 08:01 14287432                   /home/romulo/ruby/ruby-2.0.0-p353/bin/ruby
7f5a06551000-7f5a06572000 rw-p 00000000 00:00 0 
7f5a08404000-7f5a089e3000 rw-p 00000000 00:00 0                          [heap]
7fff8a246000-7fff8a267000 rw-p 00000000 00:00 0                          [stack]
7fff8a388000-7fff8a38a000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]


[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

Comments (1)

  1. Romulo Ceccon reporter

    There's some issue with the mode setting. The following doesn't segfault anymore:

    require 'libarchive'
    
    Archive.write_open_filename('a.zip', Archive::COMPRESSION_NONE, Archive::FORMAT_ZIP) do |ar|
      ar.new_entry do |entry|
        entry.mode = 0100644   # <--- here's the fix
        entry.pathname = 'a.txt'
        ar.write_header(entry)
        ar.write_data('this is going to segfault ruby')
      end
    end
    
  2. Log in to comment