Skip to content

Commit 2f64844

Browse files
committed
Fix leak when include fails in a read operation
Usually it will already fail when opening, but reads can also fail since PHP 7.4, in which case we still need to place the file handle in open_files to make sure the destructor will run on it.
1 parent 638ac2e commit 2f64844

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Include fails during read
3+
--FILE--
4+
<?php
5+
class SampleFilter extends php_user_filter { }
6+
stream_filter_register('sample.filter', SampleFilter::class);
7+
include 'php://filter/read=sample.filter/resource='. __FILE__;
8+
?>
9+
--EXPECTF--
10+
Warning: include(): Unprocessed filter buckets remaining on input brigade in %s on line %d
11+
12+
Warning: include(): Failed opening 'php://filter/read=sample.filter/resource=%s' for inclusion (include_path='%s') in %s on line %d

Zend/zend_language_scanner.l

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle)
518518
zend_string *compiled_filename;
519519

520520
if (zend_stream_fixup(file_handle, &buf, &size) == FAILURE) {
521+
/* Still add it to open_files to make destroy_file_handle work */
522+
zend_llist_add_element(&CG(open_files), file_handle);
521523
return FAILURE;
522524
}
523525

0 commit comments

Comments
 (0)