php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33285 dbase functions return garbage on certain file
Submitted: 2005-06-09 19:02 UTC Modified: 2009-01-15 17:29 UTC
Votes:4
Avg. Score:4.5 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: andrewz at springsrescuemission dot org Assigned:
Status: No Feedback Package: dBase related
PHP Version: 5CVS-2005-06-20 OS: *
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: andrewz at springsrescuemission dot org
New email:
PHP Version: OS:

 

 [2005-06-09 19:02 UTC] andrewz at springsrescuemission dot org
Description:
------------
Using PHP's dbase system cannot understand some columns and yields garbage on a certain .dbf file (http://65.108.181.103/zip.dbf).  

The .dbf was tested successfully with several other programs (OpenOffice.org 1.1.4 and Shapefile Library C).

According to file, .dbf is dbase 3 format:
$ file zip.dbf
zip.dbf: DBase 3 data file (586 records)

To enable dbase support, I used the standard Trustix 2.2 source RPM and included "--enable-dbase".

On a different system with PHP 4.3.10 and Linux 2.4.27 (Redhat 7.3), I verified the problem with dbase_get_record_with_names().  (The function dbase_get_header_info() was not available on this platform.)

Reproduce code:
---------------
$db = dbase_open("zip.dbf",0);

print_r(dbase_get_header_info($db));

if ($db) {
  $record_numbers = dbase_numrecords($db);
  for ($i = 1; $i <= $record_numbers; $i++) {
        $row = dbase_get_record_with_names($db, $i);
        print_r($row);
  }
}



Expected result:
----------------
The dbase_header_info() does not understand some columns and includes garbage (e.g. length field).  Then the dbase_get_record_with_names() has incorrect data.  

Here is output of Shapefile Library C's dbfdump -h on the same zip.dbf.  This output is good.

Field 0: Type=Double, Title=`AREA', Width=20, Decimals=5
Field 1: Type=Double, Title=`PERIMETER', Width=20, Decimals=5
Field 2: Type=Integer, Title=`ZT08_D00_', Width=11, Decimals=0
Field 3: Type=Integer, Title=`ZT08_D00_I', Width=11, Decimals=0
Field 4: Type=String, Title=`ZCTA', Width=5, Decimals=0
Field 5: Type=String, Title=`NAME', Width=90, Decimals=0
Field 6: Type=String, Title=`LSAD', Width=2, Decimals=0
Field 7: Type=String, Title=`LSAD_TRANS', Width=50, Decimals=0
                AREA            PERIMETER   ZT08_D00_  ZT08_D00_I ZCTA  NAME                                                                                       LSAD LSAD_TRANS
             0.05115              1.30727           2           1 80428 80428                                                                                      Z5   5-Digit ZCTA


Actual result:
--------------
SCRIPT OUTPUT 

Array
(
    [0] => Array
        (
            [name] => AREA
            [type] => unknown
            [length] => 1300
            [precision] => 0
            [format] => ?       "@
            [offset] => 1
        )

    [1] => Array
        (
            [name] => PERIMETER
            [type] => unknown
            [length] => 1300
            [precision] => 0
            [format] => ?       "@
            [offset] => 1301
        )


[truncated]

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-11 19:47 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-06-13 19:53 UTC] andrewz at springsrescuemission dot org
Tested with cvs-latest: problem persists.
 [2005-06-19 00:47 UTC] sniper@php.net
Can you please provide the expected result too?
Using the latest CVS the header info seems ok to me.
(no garbage in format)


 [2005-06-20 17:43 UTC] andrewz at springsrescuemission dot org
Take for example the first entry in the header:

  [0] => Array
        (
            [name] => AREA
            [type] => unknown
            [length] => 1300
            [precision] => 0
            [format] => ?       "@
            [offset] => 1
        )

The type should be a double, the length 20, and the precision 5.  Instead I get unknown, 1300, and 0.
 [2008-07-25 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-01-15 17:29 UTC] felipe@php.net
I can't reproduce it on 5.2.9-CVS:

Array
(
    [0] => Array
        (
            [name] => AREA
            [type] => float
            [length] => 20
            [precision] => 0
            [format] => %20s
            [offset] => 1
        )

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 10 05:01:27 2024 UTC