Fix parsing of large CSV files (bug #1456331).

This commit is contained in:
Michal Čihař
2006-04-10 14:17:25 +00:00
parent c53264cac0
commit e89d764725
2 changed files with 12 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ $Source$
#1467620).
* libraries/Config.class.php: Better check for server system (patch
#1462738).
* libraries/import/csv.php: Fix parsing of large CSV files (bug #1456331).
2006-04-09 Marc Delisle <lem9@users.sourceforge.net>
* tbl_replace.php, libraries/dbi/mysqli.dbi.lib.php: bug #1255923,

View File

@@ -129,13 +129,14 @@ if ($plugin_param == 'table') {
$ch = $buffer[$i];
while ($i < $len) {
// Deadlock protection
if ($lasti == $i) {
if ($lasti == $i && $lastlen == $len) {
$message = sprintf($strInvalidCSVFormat, $line);
$show_error_header = TRUE;
$error = TRUE;
break;
}
$lasti = $i;
$lastlen = $len;
// This can happen with auto EOL and \r at the end of buffer
if (!$csv_finish) {
@@ -151,6 +152,7 @@ if ($plugin_param == 'table') {
}
// Grab one field
$fallbacki = $i;
if ($ch == $csv_enclosed) {
$need_end = TRUE;
if ($i == $len - 1) {
@@ -183,12 +185,15 @@ if ($plugin_param == 'table') {
$ch = $buffer[$i];
}
if ($fail) {
$i = $fallbacki;
$ch = $buffer[$i];
break;
}
$values[] = $value;
// Need to strip trailing enclosing char?
if ($need_end && $ch == $csv_enclosed) {
if ($i == $len - 1) {
$i = $fallbacki;
$ch = $buffer[$i];
break;
}
$i++;
@@ -201,11 +206,15 @@ if ($plugin_param == 'table') {
// Go to next char
if ($ch == $csv_terminated) {
if ($i == $len - 1) {
$i = $fallbacki;
$ch = $buffer[$i];
break;
}
$i++;
$ch = $buffer[$i];
}
// If everything went okay, store value
$values[] = $value;
}
// End of line