From 3b6629c088f14c6ee8f13a009ff27441d164f334 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 26 Jun 2012 11:40:08 +0800 Subject: [PATCH] MDL-33948 file_save_draft_area_files() validates if references are allowed and allows unlimited file size --- lib/filelib.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/filelib.php b/lib/filelib.php index e814feeb4d0..523c64333d7 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -721,9 +721,16 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea if (!isset($options['maxfiles'])) { $options['maxfiles'] = -1; // unlimited } - if (!isset($options['maxbytes'])) { + if (!isset($options['maxbytes']) || $options['maxbytes'] == USER_CAN_IGNORE_FILE_SIZE_LIMITS) { $options['maxbytes'] = 0; // unlimited } + $allowreferences = true; + if (isset($options['return_types']) && !($options['return_types'] & FILE_REFERENCE)) { + // we assume that if $options['return_types'] is NOT specified, we DO allow references. + // this is not exactly right. BUT there are many places in code where filemanager options + // are not passed to file_save_draft_area_files() + $allowreferences = false; + } $draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id'); $oldfiles = $fs->get_area_files($contextid, $component, $filearea, $itemid, 'id'); @@ -755,6 +762,9 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea } if ($file->is_external_file()) { + if (!$allowreferences) { + continue; + } $repoid = $file->get_repository_id(); if (!empty($repoid)) { $file_record['repositoryid'] = $repoid; @@ -856,6 +866,9 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea } if ($file->is_external_file()) { + if (!$allowreferences) { + continue; + } $repoid = $file->get_repository_id(); if (!empty($repoid)) { $file_record['repositoryid'] = $repoid; -- 2.43.0