ID: 47002 Updated by: il...@php.net Reported By: victorjavierss at live dot com dot mx -Status: Verified +Status: Closed Bug Type: dBase related Operating System: Windows PHP Version: 5.2CVS-2009-01-04 (snap) New Comment:
This bug has been fixed in SVN. 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/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2009-12-23 04:16:13] s...@php.net Automatic comment from SVN on behalf of iliaa Revision: http://svn.php.net/viewvc/?view=revision&revision=292514 Log: Fixed bug #47002 (Field truncation when reading from dbase dbs with more then 1024 fields) ------------------------------------------------------------------------ [2009-08-31 16:35:19] sjo...@php.net Could reproduce and code shows it gets only 1024 fields. ------------------------------------------------------------------------ [2009-08-20 16:44:18] sjoerd-php at linuxonly dot nl 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; ------------------------------------------------------------------------ [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 ------------------------------------------------------------------------ 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