From b4b6eff69d27bcdbf0882c4af1fd50797aa54171 Mon Sep 17 00:00:00 2001
From: Oliver Klee <typo3-coding@oliverklee.de>
Date: Mon, 31 Jul 2023 10:37:57 +0200
Subject: [PATCH] [BUGFIX] Fix return type of GU::getMaxUploadFileSize

This method promises to return an int, but actually returns a float.

Also add a regression test.

> ./Build/Scripts/runTests.sh -s phpstanGenerateBaseline

Resolves: #101499
Releases: main, 12.4, 11.5
Change-Id: I85ca63c9b32717641d5926b16ee25e32eeb69310
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80273
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 Build/phpstan/phpstan-baseline.neon                    |  5 -----
 typo3/sysext/core/Classes/Utility/GeneralUtility.php   |  4 ++--
 .../core/Tests/Unit/Utility/GeneralUtilityTest.php     | 10 ++++++++++
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon
index 96efba98f5ab..c7f536218e1b 100644
--- a/Build/phpstan/phpstan-baseline.neon
+++ b/Build/phpstan/phpstan-baseline.neon
@@ -1745,11 +1745,6 @@ parameters:
 			count: 3
 			path: ../../typo3/sysext/core/Classes/Utility/GeneralUtility.php
 
-		-
-			message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\GeneralUtility\\:\\:getMaxUploadFileSize\\(\\) should return int but returns float\\.$#"
-			count: 1
-			path: ../../typo3/sysext/core/Classes/Utility/GeneralUtility.php
-
 		-
 			message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\GeneralUtility\\:\\:intExplode\\(\\) should return array\\<int\\> but returns array\\<int, string\\>\\.$#"
 			count: 1
diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php
index 7fce932a0e68..8c22887f0810 100644
--- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php
+++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php
@@ -2231,7 +2231,7 @@ class GeneralUtility
      * This might be handy to find out the real upload limit that is possible for this
      * TYPO3 installation.
      *
-     * @return int The maximum size of uploads that are allowed (measured in kilobytes)
+     * @return int Maximum size of uploads that are allowed in KiB (divider 1024)
      */
     public static function getMaxUploadFileSize()
     {
@@ -2244,7 +2244,7 @@ class GeneralUtility
         // If the total amount of post data is smaller (!) than the upload_max_filesize directive,
         // then this is the real limit in PHP
         $phpUploadLimit = $phpPostLimit > 0 && $phpPostLimit < $phpUploadLimit ? $phpPostLimit : $phpUploadLimit;
-        return floor($phpUploadLimit) / 1024;
+        return (int)(floor($phpUploadLimit) / 1024);
     }
 
     /**
diff --git a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
index 8d4e3e7432e5..c47a16cad969 100644
--- a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
+++ b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
@@ -4190,4 +4190,14 @@ class GeneralUtilityTest extends UnitTestCase
 
         GeneralUtility::rmdir($testFileDirectory, true);
     }
+
+    /**
+     * @test
+     */
+    public function getMaxUploadFileSizeReturnsPositiveInt(): void
+    {
+        $result = GeneralUtility::getMaxUploadFileSize();
+        self::assertIsInt($result);
+        self::assertGreaterThan(0, $result);
+    }
 }
-- 
GitLab