php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25794 Cannot open existing hash db3 file with write
Submitted: 2003-10-08 10:10 UTC Modified: 2003-11-13 03:59 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: rcovell at rolet dot com Assigned: helly (profile)
Status: Closed Package: DBM/DBA related
PHP Version: 4.3.4RC1 OS: FreeBSD 4.8
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rcovell at rolet dot com
New email:
PHP Version: OS:

 

 [2003-10-08 10:10 UTC] rcovell at rolet dot com
Description:
------------
Basically I cannot get php to open an existing (not created by php) db3 hash file when using either "w" or "c".  It seems that php is looking for a btree format.  My database is a hash file.

More information:
Trying to read/write information to an existing db3 database (sendmail aliases file).

I can read the file just fine.  But when I try to issue:

$id = dba_open ("aliases5.db", "w", "db3");

I get:
[Wed Oct  8 08:56:44 2003] [error] PHP Warning:  dba_open(aliases5.db,w): Driver initialization failed for handler: db3: Invalid argument in /usr/local/www/data/maillists/test3.php on line 3

After further testing I dumped the entire aliases db to a text file using perl and recreated a copy of it with php:

$id = dba_open ("aliases5.db", "c", "db3");

This worked when creating a new file.  The file sizes where were different from the original so performed a db3_dump on the newly created php db3 database.  It seems that php is defaulting to a btree format when trying to open with either w or c.  My output from the db3_dump on the php created db3:
VERSION=3
format=bytevalue
type=btree
HEADER=END

And from the one that sendmail created:
VERSION=3
format=bytevalue
type=hash
h_nelem=172
HEADER=END





Reproduce code:
---------------
//Note you need a hash database for this to fail
$id = dba_open ("aliases5.db", "w", "db3");
if (!$id) {
    echo "dba_open failed\n";
    exit;
}
dba_insert ("bkey", "bvalue", $id);

$key = dba_firstkey ($id);

while ($key != false)
{
    echo "<br>Key: " . $key . "->Value: " . dba_fetch ( $key, $id);
    $key = dba_nextkey ($id);
}

dba_close ($id);


Expected result:
----------------
To be able to insert into an existing (not created by php) db3 hash database.

Actual result:
--------------
[Wed Oct  8 08:56:44 2003] [error] PHP Warning:  dba_open(aliases5.db,w): Driver initialization failed for handler: db3: Invalid argument in /usr/local/www/data/maillists/test3.php on line 3

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-11 16:09 UTC] sam at readinga-z dot com
We can confirm this bug.  We are having the same problem 
using db3 files created with Apache dbmmanage.  Apache 
can not read db3 files created by PHP and PHP can not 
read the files created by dbmmanage.  Using db3_dump 
reveals that the dbmmanage files are of type 'hash' and 
that the PHP files are of type 'btree'.  We had a 
similar issue with version 4.1.2 (which we are trying to 
upgrade from)  where dbmmanage/Apache could not read the 
files created by PHP, but PHP can read the files created 
by dbmmanage.

Our error:
PHP Warning:  dba_open(/var/www/db/razdb/razpassdb,w): 
Driver initialization failed for handler: db3: Invalid 
argument in /var/www/html/old_raz/razphp/admin/
ADMIN_userrset.php on line 130

Unworking configuration is Apache 2, PHP 4.3.4 on x86 
RedHat 7.3 and 7.1
 [2003-11-12 13:46 UTC] sam at readinga-z dot com
A working fix is to alter line 90 of ext/dba/dba_db3.c 
(in your PHP source directory)
Original line:
if ((err=dbp->open(dbp, info->path, NULL, type, gmode, 
filemode)) == 0) {

Change type to DB_HASH

if ((err=dbp->open(dbp, info->path, NULL, DB_HASH, 
gmode, filemode)) == 0) {

Recompile and install PHP.
Now PHP will only be able to work with type hash db3s

PHP defaults to type DB_BTREE for creating and should 
pass DB_UNKOWN for opening. passing DB_UNKNOWN as the 
type to DB::open should be able to open a db3 of any 
type.  This code seems to work fine in older releases of 
PHP, and I can not see any differance between the older 
versions of dba_db3.c and the current release.  Possibly 
in the future an optional 'type' argument could be 
allowed to be passed through dba_open() ?
 [2003-11-13 03:59 UTC] helly@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 16:01:29 2024 UTC