From f5dc2d6903ead5ecb989a1f0021da584f4a4c29d Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 5 May 2014 20:30:06 +0000 Subject: [PATCH] Abort import if more than 100 errors are encountered. Prevents request from dying if you upload a large, bad, file --- .../class.importexport_basic_import_csv.inc.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/importexport/inc/class.importexport_basic_import_csv.inc.php b/importexport/inc/class.importexport_basic_import_csv.inc.php index 05f83cdc55..7c9e93d502 100644 --- a/importexport/inc/class.importexport_basic_import_csv.inc.php +++ b/importexport/inc/class.importexport_basic_import_csv.inc.php @@ -87,6 +87,11 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor */ protected $user = null; + /** + * Maximum number of errors or warnings before aborting + */ + const MAX_MESSAGES = 100; + /** * List of import errors */ @@ -157,7 +162,7 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor $warning = importexport_import_csv::convert($record, $record_class::$types, $app, $this->lookups, $_definition->plugin_options['convert']); - if($warning) $this->warnings[$import_csv->get_current_position()] = $warning; + if($warning) $this->warnings[$import_csv->get_current_position()] = $warning; $egw_record = new $record_class(); $egw_record->set_record($record); @@ -170,6 +175,11 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor { $this->preview_records[] = $egw_record; } + if(count($this->warnings) > self::MAX_MESSAGES || count($this->errors) > self::MAX_MESSAGES) + { + $this->errors[] = 'Too many errors, aborted'; + break; + } } return $count; } @@ -298,12 +308,14 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor // Set up HTML $rows['h1'] = $labels; + error_log("Wow, ".count($this->preview_records) . ' preveiw records'); foreach($this->preview_records as $i => $row_data) { // Convert to human-friendly importexport_export_csv::convert($row_data,$record_class::$types,$definition->application,$this->lookups); $rows[] = $row_data->get_record_array(); } + $this->preview_records = array(); return html::table($rows); }