Bug #79072 [Fbk->Opn]: If passed via a stream processor, the included file contents get corrupted

From: Date: Mon, 06 Jan 2020 19:55:54 +0000
Subject: Bug #79072 [Fbk->Opn]: If passed via a stream processor, the included file contents get corrupted
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224744@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79072&edit=1 ID: 79072 User updated by: morozov at tut dot by Reported by: morozov at tut dot by Summary: If passed via a stream processor, the included file contents get corrupted -Status: Feedback +Status: Open Type: Bug Package: Streams related Operating System: Linux PHP Version: 7.4.1 Block user comment: N Private report: N New Comment: > You are modifying the stream contents, but still report the old file size in your stream_stat() > override. This is true. > You need to adjust the size there to account for the modification made by the stream filter Not sure if that's possible given that the filtering is done by the underlying stream filter. We don't know the resulting file size upfront. > or else report the stream as un-statable. How can this be done? Removing either of the stream_stat() and url_stat() methods from the stream wrapper makes PHP unable to include the file: $ php run.php # with stream_stat removed Warning: include(): StreamProcessor::stream_stat is not implemented! in run.php on line 13 Call Stack: 0.0001 472552 1. {main}() run.php:0 $ php run.php # with url_stat removed Warning: file_exists(): StreamProcessor::url_stat is not implemented! in StreamProcessor.php on line 57 Call Stack: 0.0001 472552 1. {main}() run.php:0 0.0004 497232 2. StreamProcessor->stream_open() run.php:13 0.0004 497232 3. file_exists() StreamProcessor.php:57 Warning: include(IncludeFile.php): failed to open stream: "StreamProcessor::stream_open" call failed in run.php on line 13 Call Stack: 0.0001 472552 1. {main}() run.php:0 Warning: include(): Failed opening 'IncludeFile.php' for inclusion (include_path='.:') in run.php on line 13 Call Stack: 0.0001 472552 1. {main}() run.php:0 > Your use of stream filters here seems unnecessary. I would recommend you to simply open a > php://temp stream instead of dealing with that. Not sure I understand the suggestion. The purpose of this code is to register a file:// protocol handler that would change the file contents on the fly w/o having to modify the code that includes or reads those files. How does simply open a php://temp stream solve this problem? Previous Comments: ------------------------------------------------------------------------ [2020-01-06 18:04:39] nikic@php.net I'd say the code is incorrect. You are modifying the stream contents, but still report the old file size in your stream_stat() override. You need to adjust the size there to account for the modification made by the stream filter, or else report the stream as un-statable. PS: Your use of stream filters here seems unnecessary. I would recommend you to simply open a php://temp stream instead of dealing with that. ------------------------------------------------------------------------ [2020-01-06 16:52:59] morozov at tut dot by Description: ------------ There are some undocumented changes in PHP 7.4 which make the stream filter that worked on PHP 7.3 and earlier not work on PHP 7.4. Specifically, if an included file contents are passed through a stream filter, the file contents get corrupted (assumingly, truncated) resulting in a parse error. It is impossible to reproduce the issue using a single file, so there's a repository dedicated to reproducing the issue: https://github.com/janvernieuwe/php-vcr-debug. Interestingly, if the classes are included in the same file as the code using them, the issue is _not_ reproducible. Test script: --------------- Cannot include the files since the bug tracker detects them as spam. Expected result: ---------------- No error Actual result: -------------- PHP Parse error: syntax error, unexpected end of file in IncludeFile.php on line 7 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79072&edit=1

« previous php.bugs (#224744) next »