ID: 47002 Comment by: sjoerd-php at linuxonly dot nl Reported By: victorjavierss at live dot com dot mx Status: Open Bug Type: dBase related Operating System: Windows PHP Version: 5.2CVS-2009-01-04 (snap) New Comment:
get_dbf_head assumes a max of 1024 fields. Below is a patch which removes the 1024 limit and resizes the memory buffer if there are more than 1024 fields. --- 5.2latest/php5.2-200906261830/ext/dbase/dbf_head.c 2009-01-17 18:45:09.000000000 +0100 +++ php-5.2.10/ext/dbase/dbf_head.c 2009-08-20 18:37:56.000000000 +0200 @@ -22,7 +22,7 @@ dbhead_t *dbh; struct dbf_dhead dbhead; dbfield_t *dbf, *cur_f, *tdbf; - int ret, nfields, offset, gf_retval; + int ret, nfields, offset, gf_retval, cur_f_offset, tdbf_size; if ((dbh = (dbhead_t *)calloc(1, sizeof(dbhead_t))) == NULL) return NULL; @@ -46,14 +46,14 @@ dbhead.dbh_date[DBH_DATE_MONTH], dbhead.dbh_date[DBH_DATE_DAY]); - /* malloc enough memory for the maximum number of fields: - 32 * 1024 = 32K dBase5 (for Win) seems to allow that many */ - tdbf = (dbfield_t *)calloc(1, sizeof(dbfield_t)*1024); + /* Although 1024 fields used to be the max, bug 47002 reports more than 1024 fields. */ + tdbf_size = 1024; + tdbf = (dbfield_t *)calloc(1, sizeof(dbfield_t)*tdbf_size); offset = 1; nfields = 0; gf_retval = 0; - for (cur_f = tdbf; gf_retval < 2 && nfields < 1024; cur_f++) { + for (cur_f = tdbf; gf_retval < 2; cur_f++) { gf_retval = get_dbf_field(dbh, cur_f); if (gf_retval < 0) { @@ -66,6 +66,13 @@ offset += cur_f->db_flen; nfields++; } + if (nfields >= tdbf_size) { + cur_f_offset = cur_f - tdbf; + tdbf = realloc(tdbf, sizeof(dbfield_t) * tdbf_size * 2); + memset(tdbf + tdbf_size, '\0', tdbf_size); + tdbf_size *= 2; + cur_f = tdbf + cur_f_offset; + } } dbh->db_nfields = nfields; Previous Comments: ------------------------------------------------------------------------ [2009-01-13 06:01:04] victorjavierss at live dot com dot mx I'm guess is dBase IV ------------------------------------------------------------------------ [2009-01-13 05:59:39] victorjavierss at live dot com dot mx Ooops, i got confused with other dbf, that i'm using, but that file is over 1024 fields and y need all of them ------------------------------------------------------------------------ [2009-01-12 14:09:25] typoon at gmail dot com Victor, Are you sure this file has 1625 fields? I opened the file with DBF Viewer and I only see 1100 fields. Also I changed the logic a little bit to calculate the number of fields based on the header length and I also obtain 1100 fields. Can you please confirm the number of fields in the file? Also, what is the version of dbase you are using? Thanks! ------------------------------------------------------------------------ [2009-01-11 18:59:51] victorjavierss at live dot com dot mx Here is one of the DBF's that i'm using: http://cid-d95738776c6cf0d0.skydrive.live.com/self.aspx/.Public/USAERF07.DBF as I said it retrieves me 1024 fild instead of 1625 ------------------------------------------------------------------------ [2009-01-11 18:50:14] typoon at gmail dot com I was unable to find a free version of dBase so I can't really create the file here to simulate the issue. Could you please post a link to a .dbf file with more than 1024 fields for me please? Put like 3 or 4 records as examples on it, just so I can do all tests. Thanks! Henrique ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/47002 -- Edit this bug report at http://bugs.php.net/?id=47002&edit=1