You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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

Posted on Oct 20, 2017 10:58 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 20, 2017 5:57 PM

While using the BerkeleyDB module is indeed helpful for new code, I do have remaining concerns.

  1. DB_File
    used to work on macOS Sierra (10.12.6): In September 2017 I compiled Perl 5.26.1 from source. The
    DB_File
    module is a standard module that ships with Perl. No Berkeley DB installation was required.
    DB_File
    passed its regression tests back then. While I can compile the same Perl source on 10.13.0, the
    DB_File
    module now correctly fails its regression tests due to unexpected behavior - unless I install Berkeley DB separately.
  2. Invoking my September compilation of Perl with above test program produces the described failure. The notable thing that changed is the system library
    libSystem.dylib
    . Since the same problem affects the system Perl 5.18.2 that ships with 10.13.0, I wonder whether Perl's regression tests weren't re-run before High Sierra was shipped.
  3. When
    values
    returns about about 8MB of something for each key, I am concerned this might prove to become a vector for malicious use or intrusion.
3 replies
Question marked as Top-ranking reply

Oct 20, 2017 5:57 PM in response to VikingOSX

While using the BerkeleyDB module is indeed helpful for new code, I do have remaining concerns.

  1. DB_File
    used to work on macOS Sierra (10.12.6): In September 2017 I compiled Perl 5.26.1 from source. The
    DB_File
    module is a standard module that ships with Perl. No Berkeley DB installation was required.
    DB_File
    passed its regression tests back then. While I can compile the same Perl source on 10.13.0, the
    DB_File
    module now correctly fails its regression tests due to unexpected behavior - unless I install Berkeley DB separately.
  2. Invoking my September compilation of Perl with above test program produces the described failure. The notable thing that changed is the system library
    libSystem.dylib
    . Since the same problem affects the system Perl 5.18.2 that ships with 10.13.0, I wonder whether Perl's regression tests weren't re-run before High Sierra was shipped.
  3. When
    values
    returns about about 8MB of something for each key, I am concerned this might prove to become a vector for malicious use or intrusion.

Oct 20, 2017 11:25 AM in response to YasonX

The DB_File Perl module is intended for use with Berkeley DB v1, and the preferred choice for higher versions of Berkeley DB is the Perl BerkeleyDB module (perldoc BerkeleyDB). This module is installed in the High Sierra System Perl implementation, and High Sierra continues to use Berkeley DB 4.7.25 from May 2008, even though Oracle is on v6.2 builds.

Oct 21, 2017 11:09 AM in response to YasonX

Open a bug report at bugreporter.apple.com. Sign in with your Apple ID. You can provide a detailed description of the problem, including screenshots, etc., as part of the bug report.


When 10.13.1 is finally released, retest to see if someone caught and fixed the issue. Probably nothing you can do with the shipping 10.13.0 bits at this time, and your new compilations may be the interim solution.

Berkeley DB bug using High Sierra system Perl

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.