php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73411 dbase_pack() returns TRUE on failure
Submitted: 2016-10-28 12:14 UTC Modified: 2016-10-28 22:46 UTC
From: cmb@php.net Assigned: cmb (profile)
Status: Closed Package: dbase (PECL)
PHP Version: 7.1Git-2016-10-28 (Git) OS: *
Private report: No CVE-ID: None
 [2016-10-28 12:14 UTC] cmb@php.net
Description:
------------
Contrary to the documentation which states that dbase_pack() returns
TRUE on success and FALSE on failure, it always returns TRUE.
Furthermore, the warning message is confusing at best.


Test script:
---------------
<?php

$filename = 'test.dbf';

$db = dbase_create($filename, [['NAME', 'C', 50]]);
dbase_add_record($db, ['foo']);
dbase_add_record($db, ['bar']);
dbase_delete_record($db, 1);
dbase_close($db);

$db = dbase_open($filename, 0); // read-only
var_dump(dbase_pack($db));
dbase_close($db);


Expected result:
----------------
Warning: dbase_pack(): couldn't write to the file in %s on line %d
bool(false)

Actual result:
--------------
Warning: dbase_pack(): dbase_pack() couldn't truncate the file to the right size. Some deleted records may still be left in there in %s on line %d
bool(true)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-28 12:15 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2016-10-28 22:32 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=340781
Log: Fix #73411 :dbase_pack() returns TRUE on failure

We fix the return value according to the documentation, and raise a
warning if reading or writing fails, in which case we won't truncate the
file nor update the record count, to limit the damage.
 [2016-10-28 22:46 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 14:01:28 2024 UTC