Skip to content

Psr17Factory::createServerRequestFromGlobals() throws RuntimeException when uploaded file was already moved #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mfb opened this issue Apr 26, 2023 · 1 comment · Fixed by #233

Comments

@mfb
Copy link
Contributor

mfb commented Apr 26, 2023

PHP version: 8.2.5

Description
RuntimeException thrown by Psr17Factory::createServerRequestFromGlobals() if uploaded file was already processed by move_uploaded_file() - thus no longer exists at the tmp_name location.

RuntimeException: Unable to open "/tmp/phpPHolDZ" using mode "r": fopen(/tmp/phpPHolDZ): Failed to open stream: No such file or directory in GuzzleHttp\Psr7\Utils::GuzzleHttp\Psr7\{closure}() (line 357 of /vendor/guzzlehttp/psr7/src/Utils.php)

#0 [internal function]: GuzzleHttp\Psr7\Utils::GuzzleHttp\Psr7\{closure}(2, '...', '...', 369)
#1 /vendor/guzzlehttp/psr7/src/Utils.php(369): fopen('...', '...')
#2 /vendor/guzzlehttp/psr7/src/HttpFactory.php(56): GuzzleHttp\Psr7\Utils::tryFopen('...', '...')
#3 /vendor/php-http/discovery/src/Psr17Factory.php(124): GuzzleHttp\Psr7\HttpFactory->createStreamFromFile('...', '...')
#4 /vendor/php-http/discovery/src/Psr17Factory.php(286): Http\Discovery\Psr17Factory->createStreamFromFile('...', '...')
#5 /vendor/php-http/discovery/src/Psr17Factory.php(292): Http\Discovery\Psr17Factory->createUploadedFileFromSpec(Array)
#6 /vendor/php-http/discovery/src/Psr17Factory.php(292): Http\Discovery\Psr17Factory->createUploadedFileFromSpec(Array)
#7 /vendor/php-http/discovery/src/Psr17Factory.php(269): Http\Discovery\Psr17Factory->createUploadedFileFromSpec(Array)
#8 /vendor/php-http/discovery/src/Psr17Factory.php(184): Http\Discovery\Psr17Factory->normalizeFiles(Array)
#9 /vendor/php-http/discovery/src/Psr17Factory.php(106): Http\Discovery\Psr17Factory->buildServerRequestFromGlobals(Object(GuzzleHttp\Psr7\ServerRequest), Array, Array)

How to reproduce
Call Psr17Factory::createServerRequestFromGlobals() during a request with a file upload that was already processed by move_uploaded_file()

Possible Solution
Is it necessary to try to open uploaded files? If so can the RuntimeException be caught?

Additional context
Discovered at getsentry/sentry-php#1520

@nicolas-grekas
Copy link
Collaborator

Can you please see if #233 fixes the issue you're having?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants