MDL-29773 prevent negative unix timestamps in the files table
This commit is contained in:
committed by
Eloy Lafuente (stronk7)
parent
cfb15041cf
commit
00a3005485
@@ -652,6 +652,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;
|
||||
}
|
||||
|
||||
@@ -784,6 +794,29 @@ class file_storage {
|
||||
}
|
||||
|
||||
$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();
|
||||
|
||||
@@ -794,8 +827,8 @@ class file_storage {
|
||||
$newrecord->filepath = $file_record->filepath;
|
||||
$newrecord->filename = $file_record->filename;
|
||||
|
||||
$newrecord->timecreated = empty($file_record->timecreated) ? $now : $file_record->timecreated;
|
||||
$newrecord->timemodified = empty($file_record->timemodified) ? $now : $file_record->timemodified;
|
||||
$newrecord->timecreated = $file_record->timecreated;
|
||||
$newrecord->timemodified = $file_record->timemodified;
|
||||
$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->source = empty($file_record->source) ? null : $file_record->source;
|
||||
@@ -873,6 +906,29 @@ class file_storage {
|
||||
}
|
||||
|
||||
$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();
|
||||
|
||||
@@ -883,8 +939,8 @@ class file_storage {
|
||||
$newrecord->filepath = $file_record->filepath;
|
||||
$newrecord->filename = $file_record->filename;
|
||||
|
||||
$newrecord->timecreated = empty($file_record->timecreated) ? $now : $file_record->timecreated;
|
||||
$newrecord->timemodified = empty($file_record->timemodified) ? $now : $file_record->timemodified;
|
||||
$newrecord->timecreated = $file_record->timecreated;
|
||||
$newrecord->timemodified = $file_record->timemodified;
|
||||
$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->source = empty($file_record->source) ? null : $file_record->source;
|
||||
|
||||
Reference in New Issue
Block a user