MDL-59681 file: Stop recursive file serving

This commit is contained in:
Brendan Heywood 2022-03-21 17:50:20 +11:00
parent 0d0f09bc7f
commit 34efb9a19e

View File

@ -2678,6 +2678,8 @@ function send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring
function send_stored_file($stored_file, $lifetime=null, $filter=0, $forcedownload=false, array $options=array()) { function send_stored_file($stored_file, $lifetime=null, $filter=0, $forcedownload=false, array $options=array()) {
global $CFG, $COURSE; global $CFG, $COURSE;
static $recursion = 0;
if (empty($options['filename'])) { if (empty($options['filename'])) {
$filename = null; $filename = null;
} else { } else {
@ -2721,6 +2723,13 @@ function send_stored_file($stored_file, $lifetime=null, $filter=0, $forcedownloa
// handle external resource // handle external resource
if ($stored_file && $stored_file->is_external_file() && !isset($options['sendcachedexternalfile'])) { if ($stored_file && $stored_file->is_external_file() && !isset($options['sendcachedexternalfile'])) {
// Have we been here before?
$recursion++;
if ($recursion > 10) {
throw new coding_exception('Recursive file serving detected');
}
$stored_file->send_file($lifetime, $filter, $forcedownload, $options); $stored_file->send_file($lifetime, $filter, $forcedownload, $options);
die; die;
} }