mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
MDL-29773 prevent negative unix timestamps in the files table
This commit is contained in:
parent
694f3b74c7
commit
260c4a5b09
@ -656,6 +656,16 @@ class file_storage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($key === 'timecreated' or $key === 'timemodified') {
|
||||||
|
if (!is_number($value)) {
|
||||||
|
throw new file_exception('storedfileproblem', 'Invalid file '.$key);
|
||||||
|
}
|
||||||
|
if ($value < 0) {
|
||||||
|
//NOTE: unfortunately I make a mistake when creating the "files" table, we can not have negative numbers there, on the other hand no file should be older than 1970, right? (skodak)
|
||||||
|
$value = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$newrecord->$key = $value;
|
$newrecord->$key = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -790,6 +800,29 @@ class file_storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$now = time();
|
$now = time();
|
||||||
|
if (isset($file_record->timecreated)) {
|
||||||
|
if (!is_number($file_record->timecreated)) {
|
||||||
|
throw new file_exception('storedfileproblem', 'Invalid file timecreated');
|
||||||
|
}
|
||||||
|
if ($file_record->timecreated < 0) {
|
||||||
|
//NOTE: unfortunately I make a mistake when creating the "files" table, we can not have negative numbers there, on the other hand no file should be older than 1970, right? (skodak)
|
||||||
|
$file_record->timecreated = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$file_record->timecreated = $now;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($file_record->timemodified)) {
|
||||||
|
if (!is_number($file_record->timemodified)) {
|
||||||
|
throw new file_exception('storedfileproblem', 'Invalid file timemodified');
|
||||||
|
}
|
||||||
|
if ($file_record->timemodified < 0) {
|
||||||
|
//NOTE: unfortunately I make a mistake when creating the "files" table, we can not have negative numbers there, on the other hand no file should be older than 1970, right? (skodak)
|
||||||
|
$file_record->timemodified = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$file_record->timemodified = $now;
|
||||||
|
}
|
||||||
|
|
||||||
$newrecord = new stdClass();
|
$newrecord = new stdClass();
|
||||||
|
|
||||||
@ -800,8 +833,8 @@ class file_storage {
|
|||||||
$newrecord->filepath = $file_record->filepath;
|
$newrecord->filepath = $file_record->filepath;
|
||||||
$newrecord->filename = $file_record->filename;
|
$newrecord->filename = $file_record->filename;
|
||||||
|
|
||||||
$newrecord->timecreated = empty($file_record->timecreated) ? $now : $file_record->timecreated;
|
$newrecord->timecreated = $file_record->timecreated;
|
||||||
$newrecord->timemodified = empty($file_record->timemodified) ? $now : $file_record->timemodified;
|
$newrecord->timemodified = $file_record->timemodified;
|
||||||
$newrecord->mimetype = empty($file_record->mimetype) ? mimeinfo('type', $file_record->filename) : $file_record->mimetype;
|
$newrecord->mimetype = empty($file_record->mimetype) ? mimeinfo('type', $file_record->filename) : $file_record->mimetype;
|
||||||
$newrecord->userid = empty($file_record->userid) ? null : $file_record->userid;
|
$newrecord->userid = empty($file_record->userid) ? null : $file_record->userid;
|
||||||
$newrecord->source = empty($file_record->source) ? null : $file_record->source;
|
$newrecord->source = empty($file_record->source) ? null : $file_record->source;
|
||||||
@ -881,6 +914,29 @@ class file_storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$now = time();
|
$now = time();
|
||||||
|
if (isset($file_record->timecreated)) {
|
||||||
|
if (!is_number($file_record->timecreated)) {
|
||||||
|
throw new file_exception('storedfileproblem', 'Invalid file timecreated');
|
||||||
|
}
|
||||||
|
if ($file_record->timecreated < 0) {
|
||||||
|
//NOTE: unfortunately I make a mistake when creating the "files" table, we can not have negative numbers there, on the other hand no file should be older than 1970, right? (skodak)
|
||||||
|
$file_record->timecreated = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$file_record->timecreated = $now;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($file_record->timemodified)) {
|
||||||
|
if (!is_number($file_record->timemodified)) {
|
||||||
|
throw new file_exception('storedfileproblem', 'Invalid file timemodified');
|
||||||
|
}
|
||||||
|
if ($file_record->timemodified < 0) {
|
||||||
|
//NOTE: unfortunately I make a mistake when creating the "files" table, we can not have negative numbers there, on the other hand no file should be older than 1970, right? (skodak)
|
||||||
|
$file_record->timemodified = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$file_record->timemodified = $now;
|
||||||
|
}
|
||||||
|
|
||||||
$newrecord = new stdClass();
|
$newrecord = new stdClass();
|
||||||
|
|
||||||
@ -891,8 +947,8 @@ class file_storage {
|
|||||||
$newrecord->filepath = $file_record->filepath;
|
$newrecord->filepath = $file_record->filepath;
|
||||||
$newrecord->filename = $file_record->filename;
|
$newrecord->filename = $file_record->filename;
|
||||||
|
|
||||||
$newrecord->timecreated = empty($file_record->timecreated) ? $now : $file_record->timecreated;
|
$newrecord->timecreated = $file_record->timecreated;
|
||||||
$newrecord->timemodified = empty($file_record->timemodified) ? $now : $file_record->timemodified;
|
$newrecord->timemodified = $file_record->timemodified;
|
||||||
$newrecord->mimetype = empty($file_record->mimetype) ? mimeinfo('type', $file_record->filename) : $file_record->mimetype;
|
$newrecord->mimetype = empty($file_record->mimetype) ? mimeinfo('type', $file_record->filename) : $file_record->mimetype;
|
||||||
$newrecord->userid = empty($file_record->userid) ? null : $file_record->userid;
|
$newrecord->userid = empty($file_record->userid) ? null : $file_record->userid;
|
||||||
$newrecord->source = empty($file_record->source) ? null : $file_record->source;
|
$newrecord->source = empty($file_record->source) ? null : $file_record->source;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user