diff --git a/ChangeLog b/ChangeLog index b5b3a07cf..90bb38513 100755 --- a/ChangeLog +++ b/ChangeLog @@ -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 * tbl_replace.php, libraries/dbi/mysqli.dbi.lib.php: bug #1255923, diff --git a/libraries/import/csv.php b/libraries/import/csv.php index c45c6f031..ccaa2bf62 100644 --- a/libraries/import/csv.php +++ b/libraries/import/csv.php @@ -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