Bug #101764
closedInvalid type check for resource in \TYPO3\CMS\Core\Http\Request
100%
Description
The constructor of the Request class is supposed to accept a $body of the type "string|resource|StreamInterface|null". However, it does not accept a "resource" because it tests for the wrong string from `get_debug_type($body)`.
$this->body = match (get_debug_type($body)) {
'string', 'resource' => new Stream($body),
'null' => null,
default => throw new \InvalidArgumentException('Body must be a string stream resource identifier, a stream resource, or a StreamInterface instance', 1436717271),
};
According to the PHP documentation `get_debug_type()` will never return just the string "resource". It will instead return "resource (resourcename)" (e.g. "resource (stream)") or "resource (closed)". https://www.php.net/manual/en/function.get-debug-type.php#refsect1-function.get-debug-type-returnvalues
Since the returned string changes depending on the type of resource, it is not possible to predict exactly. This means `get_debug_type()` and `match` cannot be used to test for a resource, as `match` relies on an exact string.
The implementation in TYPO3 v11 works correctly. It is implemented a bit different, but correctly uses `is_resource($body)`.
Updated by Mathias Bolt Lesniak about 1 year ago
Come to think of it: Since only stream resources are accepted, changing "resource" to "resource (stream)" might just do the trick.
Updated by Gerrit Code Review about 1 year ago
- Status changed from New to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/80704
Updated by Gerrit Code Review about 1 year ago
Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/80704
Updated by Gerrit Code Review about 1 year ago
Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/80704
Updated by Christian Kuhn about 1 year ago
- Related to Bug #97620: PSR-7 compat fixes for core Request added
Updated by Gerrit Code Review about 1 year ago
Patch set 4 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/80704
Updated by Gerrit Code Review about 1 year ago
Patch set 5 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/80704
Updated by Gerrit Code Review about 1 year ago
Patch set 1 for branch 12.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/+/80710
Updated by Mathias Bolt Lesniak about 1 year ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 3aef30281b340b388d5edbc29f15d2b5504a467f.