Berkeley DB bug using High Sierra system Perl
The Berkeley DB functionality that is baked into
libSystem.B.dylib
, which is referenced by Perl's DB_File
module, appears to be broken when using High Sierra's own Perl. While it is possible to obtain the value for any specific key, the set operation values
returns the undef
value for all keys.Here is a small script to illustrate the problem:
use strict; use warnings; use File::Temp qw(tempfile); use DB_File; use Fcntl qw(:DEFAULT); my ($tmpfh,$tmpfn) = tempfile('trydb-XXXXXX', UNLINK => 1); die "ERROR: Unable to create temp file: $!\n" unless defined $tmpfh; my (%a,%b); tie(%a, 'DB_File', $tmpfn, O_CREAT|O_RDWR, 0666, $DB_HASH ) // die "tie $tmpfn: $!\n"; %a = ( a => 1, b => 2, c => 3 ); print "a=", $a{a}, "\n"; print "keys=[", join("], [", keys %a), "]\n"; print "values=[", join("], [", values %a), "]\n"; untie %a; print "\n"; tie(%b, 'DB_File', $tmpfn, O_RDONLY ) // die "tie $tmpfn: $!\n"; print "a=", $b{a}, "\n"; print "keys=[", join("], [", keys %b), "]\n"; print "values=[", join("], [", values %b), "]\n"; untie %b; print "\n";
The expected result is (with possible re-ordering of key-value pairs):
a=1 keys=[b], [a], [c] values=[2], [1], [3] a=1 keys=[b], [a], [c] values=[2], [1], [3]
However, the obtained result in High Sierra is, as far as visible on the console:
a=1 Use of uninitialized value within %a in join or string at try-db.pl line 17. Use of uninitialized value within %a in join or string at try-db.pl line 17. Use of uninitialized value within %a in join or string at try-db.pl line 17. keys=[a], [b], [c] values=[], [], [] a=1 Use of uninitialized value within %b in join or string at try-db.pl line 25. Use of uninitialized value within %b in join or string at try-db.pl line 25. Use of uninitialized value within %b in join or string at try-db.pl line 25. keys=[a], [b], [c] values=[], [], []
Worse, the output is very slow and confuses the terminal. Capturing stdio into a file shows that pages of bytes with value 0 are being output, a 24 MB file total from this program. Using the
/usr/bin/db_dump
tool to investigate the Perl-generated database (before $tmpfn gets auto-unlinked) fails with "unexpected file type or format" instead of showing the content.So far, I managed to work-around the problem by first compiling Berkeley DB from source, and then compiling Perl from source, pointing it to the new libdb. However, this will not fix the issue with the system Perl.
MacBook Pro, macOS High Sierra (10.13), MacBookPro8,2 2.2GHz qc-i7 8GB