Closed skaji closed 8 years ago
Hi Shoichi-
You're right, it shouldn't core dump. And this has been discussed a bit in the past.
However, there is a trade-off between speed/complexity/maintainability and safety. MDBM was designed with raw speed in mind, so it uses lots of raw offsets and pointers. Fixing the particular one you're hitting here is trivial, but there will be lots of others if you truncate at a different place, or mess with the DB in other ways.
If we add lots of boundary checking, then we slow down lots of MDBM operations. Because this kind of corruption occurs very rarely in practice (assuming folks are careful with the code that uses MDBM, e.g.: proper locking, unit-tests, and valgrind), then this extra checking doesn't usually help much. It's primarily only an issue when machines shutdown uncleanly (power failure, kernel panic, etc.).
Another alternative is to make custom versions of lots of MDBM internal functions, just for mdbm_check, which perform the extra checking. However, we don't really want to keep 2 versions of many functions (and macros), as they tend to drift and cause long term maintenance problems. So, this probably involves conditional compilation, and maybe a "debug" version of the library. A debug version could be useful for other things.
Because this is a fairly extensive task with limited gains, someone else would have to champion it. If you're interested, let me know, and we can figure out the best approach.
Thanks! .timrc
If I pass a fragment of mdbm to
mdbm_check
, then it core dumps.How to reproduce the issue:
gdb
I know head.mdbm is invalid, but I think mdbm_check should not core dump.