Bug #90063

GeneralUtility::writeFileToTypo3tempDir returns always an error even if the file is written

Added by DANIEL Rémy over 1 year ago. Updated about 1 month ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2020-01-07
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
medium
Is Regression:
Sprint Focus:

Description

TYPO3 9 + composer mode

The above code returns always an error, but the file is correctly created:

$filepath = '/var/www/html/web/typo3temp/var/tx_static404/foo.txt';
$error = \TYPO3\CMS\Core\Utility\GeneralUtility::writeFileToTypo3tempDir($filepath, 'foo');

// $error contains '"/var/www/html/web/typo3temp/var/tx_static404/" was not within directory ProjectPath + var' instead of NULL

The issue is that writeFileToTypo3tempDir checks if the directory of the file is within two allowed pathes:
- Environment::getPublicPath() + "/typo3temp/"
- Environment::getVarPath()

But even if the file is written in the within the first path, the second path is still checked.

The foreach should break as soon as the file is successfully created, and returns NULL error message, as expected.


Files

#1

Updated by Gerrit Code Review over 1 year ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62828

#2

Updated by Gerrit Code Review over 1 year ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62828

#3

Updated by Gerrit Code Review over 1 year ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62828

#4

Updated by Gerrit Code Review over 1 year ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62828

#5

Updated by Anja Leichsenring over 1 year ago

  • Status changed from Under Review to Rejected

the use case described can not be realized anymore with the function. The error report could not be verified.

Closed by request of author.

#6

Updated by DANIEL Rémy over 1 year ago

I requested the close of this issue and the associated review because the usecase I had changed.

But, I reproduce the error described above with this simple lines of code, on TYPO3 9.5, in composer mode:

if (\TYPO3\CMS\Core\Core\Environment::isComposerMode()) {
    $filename = \TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3temp/test.txt';
    $error = \TYPO3\CMS\Core\Utility\GeneralUtility::writeFileToTypo3tempDir($filename, 'foo');
    var_dump(file_exists($filename)); // true
    var_dump($error); // "/var/www/html/web/typo3temp/" was not within directory ProjectPath + var
    @unlink($filename);
}

There is 3 places in the core where the error could rise (using GU::writeFileToTypo3tempDir() to write in the public/typo3temp dir).
Fortunately the return of GU::writeFileToTypo3tempDir() is not tested there.

GeneralUtility::writeJavaScriptContentToTemporaryFile()
GeneralUtility::writeStyleSheetContentToTemporaryFile()
\TYPO3\CMS\Frontend\Page\PageGenerator::inline2TempFile()

Also, I would argue that GU::writeFileToTypo3tempDir() is not a good name anymore.
The method should be called GU::writeFileToVarDir().

Cheers.

#7

Updated by Lina Wolf 9 months ago

I can reproduce the error, cost me several hours of debugging. I get the error in 9.5.21 in Extension https://github.com/sabbelasichon/bzga_beratungsstellensuche when importing data containing images

Attached patch fixed it for me.

#8

Updated by Marieke de Bruin 2 months ago

I can reproduce this issue on 10.4.14, please reopen this issue.

#9

Updated by Gerrit Code Review 2 months ago

  • Status changed from Rejected to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/68721

#10

Updated by Gerrit Code Review about 2 months ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/68721

#11

Updated by Gerrit Code Review about 1 month ago

Patch set 1 for branch 10.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/68868

#12

Updated by Riny van Tiggelen about 1 month ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
#13

Updated by Benni Mack about 1 month ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF