summaryrefslogtreecommitdiff
path: root/main/streams/streams.c
Commit message (Collapse)AuthorAgeFilesLines
* Change Zend Stream API to use zend_string* instead of char*.Dmitry Stogov2021-03-161-1/+9
| | | | | This allows to eliminate re-calculation of string lenght and hash value. See the detailed list of changes in UPGRADING.INTERNALS.
* Improve SPL directory and stat() cache using zend_srting* instead of char*Dmitry Stogov2021-02-261-36/+1
|
* Merge branch 'PHP-7.4' into PHP-8.0Christoph M. Becker2021-02-221-1/+1
|\ | | | | | | | | * PHP-7.4: Fix #75776: Flushing streams with compression filter is broken
| * Fix #75776: Flushing streams with compression filter is brokenChristoph M. Becker2021-02-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | First, the `bzip2.compress` filter has the same issue as `zlib.deflate` so we port the respective fix[1] to ext/bz2. Second, there is still an issue, if a stream with an attached compression filter is flushed before it is closed, without any writes in between. In that case, the compression is never finalized. We fix this by enforcing a `_php_stream_flush()` with the `closing` flag set in `_php_stream_free()`, whenever a write filter is attached. This call is superfluous for most write filters, but does not hurt, even when it is unnecessary. [1] <http://git.php.net/?p=php-src.git;a=commit;h=20e75329f2adb11dd231852c061926d0e4080929> Closes GH-6703.
* | Merge branch 'PHP-7.4' into PHP-8.0Christoph M. Becker2020-12-231-1/+2
|\ \ | |/ | | | | | | * PHP-7.4: Fix #80384: limit read buffer size
| * Fix #80384: limit read buffer sizeAdam Seitz2020-12-231-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | In the case of a stream with no filters, php_stream_fill_read_buffer only reads stream->chunk_size into the read buffer. If the stream has filters attached, it could unnecessarily buffer a large amount of data. With this change, php_stream_fill_read_buffer only proceeds until either the requested size or stream->chunk_size is available in the read buffer. Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de> Closes GH-6444.
* | Merge branch 'PHP-7.4' into PHP-8.0Christoph M. Becker2020-12-081-1/+1
|\ \ | |/ | | | | | | * PHP-7.4: Fix #77069: stream filter loses final block of data
| * Fix #77069: stream filter loses final block of dataChristoph M. Becker2020-12-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reading from a stream may return greater than zero, but nonetheless the stream's EOF flag may have been set. We have to cater to this condition by setting the close flag for filters. We also have to cater to that change in the zlib.inflate filter: If `inflate()` is called with flush mode `Z_FINISH`, but the output buffer is not large enough to inflate all available data, it fails with `Z_BUF_ERROR`. However, `Z_BUF_ERROR` is not fatal; in fact, the zlib manual states: "If deflate returns with Z_OK or Z_BUF_ERROR, this function must be called again with Z_FINISH and more output space (updated avail_out) but no more input data, until it returns with Z_STREAM_END or an error." Hence, we do so. Closes GH-6001.
* | Clear error flag instead of toggling itChristoph M. Becker2020-09-231-6/+6
| | | | | | | | | | | | | | The toggling of the `REPORT_ERRORS` looks fishy, and likely was intented as clearing. Closes GH-6190.
* | Merge branch 'PHP-7.4' into masterChristoph M. Becker2020-09-211-17/+36
|\ \ | |/ | | | | | | * PHP-7.4: Fix mmap copying
| * Fix mmap copyingChristoph M. Becker2020-09-211-17/+36
| | | | | | | | | | | | | | | | | | | | Instead of attempting to map large files into memory at once, we map chunks of at most `PHP_STREAM_MMAP_MAX` bytes, and repeat that until we hit the point where `php_stream_seek()` fails (see bug 54902), and copy the rest of the file by reading and writing small chunks. We also fix the mapping behavior for zero bytes on Windows, which did not error (as with `mmap()`), but would have mapped the remaining file.
* | ValueError for empty path in stream codeGeorge Peter Banyard2020-07-311-1/+1
| | | | | | | | Closes GH-5902
* | Remove proto comments from C filesMax Semenik2020-07-061-10/+5
| | | | | | | | Closes GH-5758
* | Fix expression warnings and break warningstwosee2020-06-071-3/+3
| | | | | | | | Close GH-5675.
* | Merge branch 'PHP-7.4'Nikita Popov2020-04-141-0/+6
|\ \ | |/ | | | | | | * PHP-7.4: Fixed bug #79468
| * Merge branch 'PHP-7.3' into PHP-7.4Nikita Popov2020-04-141-0/+6
| |\ | | | | | | | | | | | | * PHP-7.3: Fixed bug #79468
| | * Fixed bug #79468dinosaur2020-04-141-0/+6
| | | | | | | | | | | | Close the stream filter resources when removing them from the stream.
* | | Merge branch 'PHP-7.4'Nikita Popov2020-01-231-2/+9
|\ \ \ | |/ / | | | | | | | | | | | | * PHP-7.4: Fixed bug #78902 Add unit test for bug #78902
| * | Merge branch 'PHP-7.3' into PHP-7.4Nikita Popov2020-01-231-2/+9
| |\ \ | | |/ | | | | | | | | | | | | * PHP-7.3: Fixed bug #78902 Add unit test for bug #78902
| | * Fixed bug #78902liudaixiao2020-01-231-2/+9
| | |
* | | Make error messages more consistent by fixing capitalizationMáté Kocsis2020-01-171-4/+4
| | | | | | | | | | | | Closes GH-5066 As a first step, let's capitalize their initial letter when it is applicable.
* | | Merge branch 'PHP-7.4'Nikita Popov2019-12-301-0/+3
|\ \ \ | |/ / | | | | | | | | | * PHP-7.4: Properly propagate url_stat exceptions during include
| * | Properly propagate url_stat exceptions during includeNikita Popov2019-12-301-0/+3
| | | | | | | | | | | | | | | Make sure we abort operations early, and that we don't emit additional warnings or errors if an exception has been thrown.
* | | Don't use chunking for stream writesNikita Popov2019-10-301-7/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We're currently splitting up large writes into 8K size chunks, which adversely affects I/O performance in some cases. Splitting up writes doesn't make a lot of sense, as we already must have a backing buffer, so there is no memory/performance tradeoff to be made here. This change disables the write chunking at the stream layer, but retains the current retry loop for partial writes. In particular network writes will typically only write part of the data for large writes, so we need to keep the retry loop to preserve backwards compatibility. If issues due to this change turn up, chunking should be reintroduced at lower levels where it is needed to avoid issues for specific streams, rather than unnecessarily enforcing it for all streams.
* | | Merge branch 'PHP-7.4'Nikita Popov2019-10-081-1/+7
|\ \ \ | |/ /
| * | Merge branch 'PHP-7.3' into PHP-7.4Nikita Popov2019-10-081-1/+7
| |\ \ | | |/
| | * Check for exception after applying stream filtersNikita Popov2019-10-081-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | This makes the stream opening actually fail, and avoids assertion failures when we tokenize with EG(exception) set. Also avoid throwing an additional warning after an exception has already been thrown.
* | | Merge branch 'PHP-7.4'Joe Watkins2019-10-031-4/+0
|\ \ \ | |/ / | | | | | | | | | * PHP-7.4: Fix #76859 stream_get_line skips data if used with data-generating filter
| * | Merge branch 'PHP-7.3' into PHP-7.4Joe Watkins2019-10-031-4/+0
| |\ \ | | |/ | | | | | | | | | * PHP-7.3: Fix #76859 stream_get_line skips data if used with data-generating filter
| | * Merge branch 'PHP-7.2' into PHP-7.3Joe Watkins2019-10-031-4/+0
| | |\ | | | | | | | | | | | | | | | | * PHP-7.2: Fix #76859 stream_get_line skips data if used with data-generating filter
| | | * Fix #76859 stream_get_line skips data if used with data-generating filterKonstantin Kopachev2019-10-031-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | stream_get-line repeatedly calls php_stream_fill_read_buffer until enough data is accumulated in buffer. However, when stream contains filters attached to it, then each call to fill buffer essentially resets buffer read/write pointers and new data is written over old. This causes stream_get_line to skip parts of data from stream This patch fixes such behavior, so fill buffer call will append.
* | | | Remove unused mmap_file + mmap_len from basic_globalsNikita Popov2019-09-271-1/+1
| | | |
* | | | Remove mention of PHP major version in Copyright headersGabriel Caruso2019-09-251-2/+0
|/ / / | | | | | | | | | Closes GH-4732.
* | | Fixed bug #78506Nikita Popov2019-09-111-18/+16
| | |
* | | Fixed bug #78396Nikita Popov2019-08-121-1/+1
| | |
* | | Merge branch 'PHP-7.3' into PHP-7.4Nikita Popov2019-07-291-1/+6
|\ \ \ | |/ /
| * | Merge branch 'PHP-7.2' into PHP-7.3Nikita Popov2019-07-291-1/+6
| |\ \ | | |/
| | * Fix bug #78326Albert Casademont2019-07-291-1/+6
| | | | | | | | | | | | | | | Similar to what fread() does, truncate the stream_get_contents() result if the original buffer was way too large.
* | | Throw notice for plain wrapper fread/fwrite errorsNikita Popov2019-07-251-1/+3
| | | | | | | | | | | | Similar to what is done for socket read/write errors.
* | | Report errors from stream read and write operationsNikita Popov2019-07-221-66/+115
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The php_stream_read() and php_stream_write() functions now return an ssize_t value, with negative results indicating failure. Functions like fread() and fwrite() will return false in that case. As a special case, EWOULDBLOCK and EAGAIN on non-blocking streams should not be regarded as error conditions, and be reported as successful zero-length reads/writes instead. The handling of EINTR remains unclear and is internally inconsistent (e.g. some code-paths will automatically retry on EINTR, while some won't). I'm landing this now to make sure the stream wrapper ops API changes make it into 7.4 -- however, if the user-facing changes turn out to be problematic we have the option of clamping negative returns to zero in php_stream_read() and php_stream_write() to restore the old behavior in a relatively non-intrusive manner.
* | | Fix use-after-free in stream freeing during shutdownNikita Popov2019-06-271-6/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Streams will be freed in an unpredictable order during shutdown. Ignore explicit calls to php_stream_close() entirely to avoid use-after-free -- instead let the stream resource destructor deal with it. We have to account for a few special cases: * Enclosed streams should be freed, as the resource destructor will forward to the enclosing stream. * Stream cookies also directly free streams, because we delegate to the cookie destruction if one exists. * Mysqlnd also directly frees streams, because it explicitly removes stream resources (because mysqlnd!)
* | | Avoid memcpy UB in streamsNikita Popov2019-06-191-1/+3
| | |
* | | Merge branch 'PHP-7.3' into PHP-7.4Nikita Popov2019-02-111-0/+2
|\ \ \ | |/ /
| * | Merge branch 'PHP-7.2' into PHP-7.3Nikita Popov2019-02-111-0/+2
| |\ \ | | |/
| | * Fix #77552: Uninitialized buffer in stat functionsjohnstevenson2019-02-111-0/+2
| | |
| | * year++Xinchen Hui2018-01-021-1/+1
| | |
* | | Remove local variablesPeter Kokot2019-02-031-9/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch removes the so called local variables defined per file basis for certain editors to properly show tab width, and similar settings. These are mainly used by Vim and Emacs editors yet with recent changes the once working definitions don't work anymore in Vim without custom plugins or additional configuration. Neither are these settings synced across the PHP code base. A simpler and better approach is EditorConfig and fixing code using some code style fixing tools in the future instead. This patch also removes the so called modelines for Vim. Modelines allow Vim editor specifically to set some editor configuration such as syntax highlighting, indentation style and tab width to be set in the first line or the last 5 lines per file basis. Since the php test files have syntax highlighting already set in most editors properly and EditorConfig takes care of the indentation settings, this patch removes these as well for the Vim 6.0 and newer versions. With the removal of local variables for certain editors such as Emacs and Vim, the footer is also probably not needed anymore when creating extensions using ext_skel.php script. Additionally, Vim modelines for setting php syntax and some editor settings has been removed from some *.phpt files. All these are mostly not relevant for phpt files neither work properly in the middle of the file.
* | | Remove yearly range from copyright noticeZeev Suraski2019-01-301-1/+1
| | |
* | | Replace zend_hash_apply... with ZEND_HASH_FOREACH...Dmitry Stogov2018-12-191-1/+5
|/ /
* | Remove unused Git attributes identPeter Kokot2018-07-251-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The $Id$ keywords were used in Subversion where they can be substituted with filename, last revision number change, last changed date, and last user who changed it. In Git this functionality is different and can be done with Git attribute ident. These need to be defined manually for each file in the .gitattributes file and are afterwards replaced with 40-character hexadecimal blob object name which is based only on the particular file contents. This patch simplifies handling of $Id$ keywords by removing them since they are not used anymore.