Bug #90063

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

Added by DANIEL Rémy about 2 months ago. Updated about 2 months ago.

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

0%

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.

History

#1 Updated by Gerrit Code Review about 2 months 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 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/+/62828

#3 Updated by Gerrit Code Review about 2 months 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 about 2 months 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 about 2 months 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 about 2 months 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.

Also available in: Atom PDF