#2 segfault loading text version of the database

open-postponed
ChriS
None
5
2008-03-23
2006-06-30
Anonymous
No

problem parsing the libmagic text database
(/etc/file/magic), while the libmagic binary database
(/etc/file/magic.mgc) works.

the problem happened running mldonkey-cvs20060626 on a
slackware-current-20060602 using file-4.17 (that does
not comes for default with the binary database)

the mldonkey segfaults while loading, the code is
around here, on mldonkey cvs:
./src/utils/lib/magic.ml.in
./src/utils/lib/magic_magic.ml
./src/utils/lib/magic_nomagic.ml
./src/utils/lib/magiclib.ml
./src/utils/lib/magiclib.mli
./src/utils/lib/magiclib_stub.c

Discussion

  • tanaydin

    tanaydin - 2006-08-04

    Logged In: YES
    user_id=220888

    same here... is there any workaround before fix ?

     
  • spiralvoice

    spiralvoice - 2006-09-01

    Logged In: YES
    user_id=559957

    This bug is also present on Debian:
    http://bugs.debian.org/378831

     
  • spiralvoice

    spiralvoice - 2006-11-19

    Logged In: YES
    user_id=559957
    Originator: NO

    The bug is still present when using the updated files from September or the original ones.
    They make no difference. this time I tested on a fresh installed Slackware 11.0

    # file -v
    file-4.17
    magic file from /etc/file/magic

    # ls -la /etc/file/
    total 480
    -rw-r--r-- 1 root root 443077 2006-08-01 05:13 magic
    -rw-r--r-- 1 root root 31136 2006-08-01 05:13 magic.mime

    open("/etc/file/magic.mgc", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
    open("/etc/file/magic", O_RDONLY|O_LARGEFILE) = 13
    fstat64(13, {st_mode=S_IFREG|0644, st_size=443077, ...}) = 0
    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x404df000
    read(13, "# Magic\n# Magic data for file(1)"..., 4096) = 4096
    --- SIGSEGV (Segmentation fault) @ 0 (0) ---

    After compiling magic.mgc: "cd /etc/file && file -C" the segfault disappears
    so Ocaml-Magic in its current state fails with the text version of the libmagic database.

    # ls -la /etc/file/
    total 1428
    -rw-r--r-- 1 root root 443077 2006-08-01 05:13 magic
    -rw-r--r-- 1 root root 966016 2006-11-19 01:16 magic.mgc
    -rw-r--r-- 1 root root 31136 2006-08-01 05:13 magic.mime

     
  • spiralvoice

    spiralvoice - 2006-11-19

    Logged In: YES
    user_id=559957
    Originator: NO

    Debug5 is reached, before debug6 is reached the segfault occurs

    #define LOAD(fname) \ fprintf(stdout, "debug3\n"); \ magic_t cookie = COOKIE_VAL(c); \ fprintf(stdout, "debug4\n"); \ \ if (cookie == NULL) caml_invalid_argument("Magiclib.load"); \ fprintf(stdout, "debug5\n"); \ if (magic_load(cookie, fname) < 0) \ raise_on_error("Magiclib.load: ", cookie); \ fprintf(stdout, "debug6\n"); \ CAMLreturn(Val_unit)

     
  • spiralvoice

    spiralvoice - 2006-11-19

    Logged In: YES
    user_id=559957
    Originator: NO

    This time on Debian Etch here is a gdb backtrace using debug libraries libc6-dbg
    and http://people.debian.org/~smimram/mldonkey/libmagic1_4.17-2_i386.deb
    I reproduced the bug because I removed /usr/share/file/*.mgc

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread 16384 (LWP 29959)]
    0xa7c58a0d in *__GI_memset (dstpp=0x85d45a0, c=<value optimized out>, len=128) at ../sysdeps/i386/memset.c:65
    65 ../sysdeps/i386/memset.c: Datei oder Verzeichnis nicht gefunden.
    in ../sysdeps/i386/memset.c
    (gdb) bt
    #0 0xa7c58a0d in *__GI_memset (dstpp=0x85d45a0, c=<value optimized out>, len=128) at ../sysdeps/i386/memset.c:65
    #1 0xa7e7816d in apprentice_file (ms=0x8553dc8, magicp=0xafca3ccc, nmagicp=0xafca3cc8,
    fn=0x8550073 "/usr/share/file/magic", action=0) at apprentice.c:567
    #2 0xa7e79615 in file_apprentice (ms=0x8553dc8, fn=0x8550073 "/usr/share/file/magic", action=0)
    at apprentice.c:183
    #3 0xa7e776c2 in magic_load (ms=0x8553dc8, magicfile=0x0) at magic.c:156
    #4 0x0832e129 in ?? ()

     
  • ChriS

    ChriS - 2008-03-23
    • assigned_to: nobody --> chris_77
     
  • ChriS

    ChriS - 2008-03-23

    Logged In: YES
    user_id=1061649
    Originator: NO

    May you check again with OCaml 3.10 and the version 0.7.1 of ocaml-magic?

     
  • ChriS

    ChriS - 2008-03-23
    • status: open --> open-postponed
     
  • spiralvoice

    spiralvoice - 2008-03-23

    Logged In: YES
    user_id=559957
    Originator: NO

    I will test it, but your code

    (* FIXME: "/usr/share/file/magic" is a temporary choice until the
    toplevel segfault is solved. *)
    let filenames = (if filenames = [] then ["/usr/share/file/magic"]
    else filenames) in

    is not sufficient because, for example, on Debian Sarge the magic
    database is in /usr/share/misc/file/ and on FreeBSD 7.0 it can
    be found in /usr/share/misc/.

     
  • spiralvoice

    spiralvoice - 2008-03-23

    Logged In: YES
    user_id=559957
    Originator: NO

    I used your new files in MLDonkey on Debian and moved /usr/share/file
    to /usr/share/file.old to trigger the bug.

    This is the gdb backtrace:

    , 4: Warning using regular magic file `/usr/share/file/magic.mime'

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread 0xb7bd2ae0 (LWP 6774)]
    0x0832342d in raise_magic_failure (msg=0x8353aff "Magic.load") at src/utils/lib/magiclib_stub.c:57
    57 raise_with_string(*exn, (char *) msg);
    (gdb) bt
    #0 0x0832342d in raise_magic_failure (msg=0x8353aff "Magic.load") at src/utils/lib/magiclib_stub.c:57
    #1 0x0832355b in ocaml_magic_load_default (c=-1215808820) at src/utils/lib/magiclib_stub.c:301
    #2 0x0820f74b in camlMagiclib__load_101 ()
    #3 0xb7883acc in ?? ()
    #4 0x0820fa85 in camlMagic_magic__magic_cookie_mime_70 ()
    #5 0x0820fa95 in camlMagic_magic__magic_cookie_mime_70 ()

     
  • ChriS

    ChriS - 2008-03-23

    Logged In: YES
    user_id=1061649
    Originator: NO

    > let filenames = (if filenames = [] then ["/usr/share/file/magic"]
    > else filenames) in

    I removed this hack.

     
  • ChriS

    ChriS - 2008-03-23

    Logged In: YES
    user_id=1061649
    Originator: NO

    > moved /usr/share/file to /usr/share/file.old to trigger the bug.

    May you provide more details? I just did that and got (in the toploop):

    # let c = Magic.make [];;
    /etc/magic, 4: Warning using regular magic file `/usr/share/file/magic'
    Exception: Magic.Failure "Magic.load".

    which is what is expected. I can also do

    # Magic.load c ["/usr/share/file/magic.mime"];;

    without problem.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks