Project

General

Profile

Actions

Bug #101764

closed

Invalid type check for resource in \TYPO3\CMS\Core\Http\Request

Added by Mathias Bolt Lesniak 8 months ago. Updated 8 months ago.

Status:
Resolved
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2023-08-27
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
12
PHP Version:
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

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)`.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #97620: PSR-7 compat fixes for core RequestClosedLarry Garfield2022-05-12

Actions
Actions #1

Updated by Mathias Bolt Lesniak 8 months ago

Come to think of it: Since only stream resources are accepted, changing "resource" to "resource (stream)" might just do the trick.

Actions #2

Updated by Gerrit Code Review 8 months 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

Actions #3

Updated by Gerrit Code Review 8 months 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

Actions #4

Updated by Gerrit Code Review 8 months 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

Actions #5

Updated by Christian Kuhn 8 months ago

  • Related to Bug #97620: PSR-7 compat fixes for core Request added
Actions #6

Updated by Gerrit Code Review 8 months 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

Actions #7

Updated by Gerrit Code Review 8 months 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

Actions #8

Updated by Gerrit Code Review 8 months 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

Actions #9

Updated by Mathias Bolt Lesniak 8 months ago

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

Also available in: Atom PDF