Package: ocaml
Version: 3.11.2-1
Severity: normal

While testing how the Dbm can be used I got 2 errors with a corrupt dbm file.
The test program DOES have the entire ML code wrapped in a try block, which
works:
$ ocaml dbm.cma foo.ml
OK
Exception: Not found

Now copy the (intentionally) corrupted dbm file attached to this bugreport:
$ cp corrupt.pag data.db.pag

1. If the DB is corrupt I get a gdbm fatal error that kills the ML program
$ ocaml dbm.cma foo.ml
gdbm fatal: lseek error

I think gdbm has a way to set a fatal error hook, which OCaml apparently isn't
using.

2. And under some circumstances OCaml even segfaults with a corrupt dbm file
(although it might be a bug in gdbm, I don't know):
$ ocamlc dbm.cma foo.ml
$ ocaml
        Objective Caml version 3.11.2

# #load "dbm.cma";;
# #load "foo.ml";;
File foo.ml is not a bytecode object file.
# #load "foo.cmo";;
Segmentation fault

This doesn't immediately segfault, but gives valgrind warning:
valgrind /usr/bin/ocamlrun /usr/bin/ocaml
==12557== Memcheck, a memory error detector
==12557== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==12557== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright 
info
==12557== Command: /usr/bin/ocamlrun /usr/bin/ocaml
==12557== 
        Objective Caml version 3.11.2

# #load "dbm.cma";;
# #load "foo.cmo";;
==12557== Invalid read of size 8
==12557==    at 0x3CEAA03488: _gdbm_get_bucket (in /usr/lib/libgdbm.so.3.0.0)
==12557==    by 0x3CEAA04048: _gdbm_findkey (in /usr/lib/libgdbm.so.3.0.0)
==12557==    by 0x3CEAA02156: gdbm_fetch (in /usr/lib/libgdbm.so.3.0.0)
==12557==    by 0x5494434: dbm_fetch (in /usr/lib/libgdbm_compat.so.3.0.0)
==12557==    by 0x5291ED2: caml_dbm_fetch (in 
/usr/lib/ocaml/stublibs/dllmldbm.so)
==12557==    by 0x41AFDE: caml_interprete (in /usr/bin/ocamlrun)
==12557==    by 0x41C8B9: caml_main (in /usr/bin/ocamlrun)
==12557==    by 0x419C0F: main (in /usr/bin/ocamlrun)
==12557==  Address 0x5127838 is not stack'd, malloc'd or (recently) free'd
==12557== 
OK

Here is foo.ml:
Printexc.record_backtrace true;
try
    let db = Dbm.opendbm "data.db" [Dbm.Dbm_rdwr; Dbm.Dbm_create] 0o666 in
        print_string "OK\n";
        print_string (Dbm.find db "data");
    Dbm.close db
with e ->
    Printf.eprintf "Exception: %s\n" (Printexc.to_string e);
    Printexc.print_backtrace stderr;

-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (990, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.34-rc5-00118-gf259493 (SMP w/4 CPU cores; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages ocaml depends on:
ii  libx11-dev                    2:1.3.3-3  X11 client-side library (developme
ii  ocaml-base [ocaml-base-3.11.2 3.11.2-1   Runtime system for OCaml bytecode 
ii  ocaml-nox [ocaml-nox-3.11.2]  3.11.2-1   ML implementation with a class-bas

ocaml recommends no packages.

Versions of packages ocaml suggests:
pn  tcl8.5-dev                    <none>     (no description available)
pn  tk8.5-dev                     <none>     (no description available)

-- no debconf information

Attachment: corrupt.db.pag
Description: application/gdbm

Reply via email to