From e440f477841f0996fa4520693302b230005d5190 Mon Sep 17 00:00:00 2001
From: Nicole Cordes <typo3@cordes.co>
Date: Tue, 4 Apr 2017 15:26:43 +0200
Subject: [PATCH] [BUGFIX] Prevent uncaught exception in Import/Export
 controller

Currently an error is thrown if no post data was sent to the
ImportExportController. This can easily happen if a t3d file should
be uploaded but is larger than the configured post_max_size of the
server. This patch checks the incoming information, sets the import
action as default and displays an information to the user that he/she
may have tried to upload a file that was too large.

Resolves: #80681
Releases: master, 8.7, 7.6
Change-Id: I561dbf6abd74acace3eff179a513b4f9128d792d
Reviewed-on: https://review.typo3.org/52363
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
---
 .../Controller/ImportExportController.php        | 16 ++++++++++++++++
 .../Resources/Private/Language/locallang.xlf     |  6 ++++++
 2 files changed, 22 insertions(+)

diff --git a/typo3/sysext/impexp/Classes/Controller/ImportExportController.php b/typo3/sysext/impexp/Classes/Controller/ImportExportController.php
index 15cb475e4a5e..d5abba3c6f51 100644
--- a/typo3/sysext/impexp/Classes/Controller/ImportExportController.php
+++ b/typo3/sysext/impexp/Classes/Controller/ImportExportController.php
@@ -195,6 +195,22 @@ class ImportExportController extends BaseScriptClass
 
         // Input data grabbed:
         $inData = GeneralUtility::_GP('tx_impexp');
+        if ($inData === null) {
+            // This happens if the post request was larger than allowed on the server
+            // We set the import action as default and output a user information
+            $inData = [
+                'action' => 'import',
+            ];
+            $flashMessage = GeneralUtility::makeInstance(
+                FlashMessage::class,
+                $this->getLanguageService()->getLL('importdata_upload_nodata'),
+                $this->getLanguageService()->getLL('importdata_upload_error'),
+                FlashMessage::ERROR
+            );
+            $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
+            $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
+            $defaultFlashMessageQueue->enqueue($flashMessage);
+        }
         if (!array_key_exists('excludeDisabled', $inData)) {
             // flag doesn't exist initially; state is on by default
             $inData['excludeDisabled'] = 1;
diff --git a/typo3/sysext/impexp/Resources/Private/Language/locallang.xlf b/typo3/sysext/impexp/Resources/Private/Language/locallang.xlf
index 818ae8dce449..ccfa1ba30a78 100644
--- a/typo3/sysext/impexp/Resources/Private/Language/locallang.xlf
+++ b/typo3/sysext/impexp/Resources/Private/Language/locallang.xlf
@@ -309,6 +309,12 @@
 			<trans-unit id="importdata_upload">
 				<source>Upload</source>
 			</trans-unit>
+			<trans-unit id="importdata_upload_error">
+				<source>Upload error</source>
+			</trans-unit>
+			<trans-unit id="importdata_upload_nodata">
+				<source>The import module hasn't received any data. This may occur due to a file upload with a large file. Please check the file size of your uploaded file with the server's post_max_size and upload_max_filesize configuration.</source>
+			</trans-unit>
 			<trans-unit id="importdata_metaData">
 				<source>Meta data:</source>
 			</trans-unit>
-- 
GitLab