iliaa Wed, 23 Dec 2009 04:16:13 +0000 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) Bug: http://bugs.php.net/47002 (Verified) Fields truncated Changed paths: U php/php-src/branches/PHP_5_2/NEWS U php/php-src/branches/PHP_5_2/ext/dbase/dbf_head.c Modified: php/php-src/branches/PHP_5_2/NEWS =================================================================== --- php/php-src/branches/PHP_5_2/NEWS 2009-12-23 00:41:20 UTC (rev 292513) +++ php/php-src/branches/PHP_5_2/NEWS 2009-12-23 04:16:13 UTC (rev 292514) @@ -11,6 +11,8 @@ - Fixed bug #49851 (http wrapper breaks on 1024 char long headers). (Ilia) - Fixed bug #45599 (strip_tags() truncates rest of string with invalid attribute). (Ilia, hradtke) +- Fixed bug #47002 (Field truncation when reading from dbase dbs with more + then 1024 fields). (Ilia, sjoerd-php at linuxonly dot nl) 17 Dec 2009, PHP 5.2.12 - Updated timezone database to version 2009.19 (2009s). (Derick) Modified: php/php-src/branches/PHP_5_2/ext/dbase/dbf_head.c =================================================================== --- php/php-src/branches/PHP_5_2/ext/dbase/dbf_head.c 2009-12-23 00:41:20 UTC (rev 292513) +++ php/php-src/branches/PHP_5_2/ext/dbase/dbf_head.c 2009-12-23 04:16:13 UTC (rev 292514) @@ -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,13 @@ 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); - + 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) { @@ -61,6 +60,15 @@ free(tdbf); return NULL; } + + 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; + } + if (gf_retval != 2 ) { cur_f->db_foffset = offset; offset += cur_f->db_flen;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php