修复分片上传参数过滤不严的BUG

pull/261/MERGE
Karson 2021-04-01 17:36:22 +08:00
parent a58a147143
commit 454fdcded9
1 changed files with 36 additions and 17 deletions

View File

@ -76,6 +76,7 @@ class Upload
$this->file = $file; $this->file = $file;
$this->fileInfo = $fileInfo; $this->fileInfo = $fileInfo;
$this->checkExecutable();
} }
protected function checkExecutable() protected function checkExecutable()
@ -171,6 +172,9 @@ class Upload
*/ */
public function clean($chunkid) public function clean($chunkid)
{ {
if (!preg_match('/^[a-z0-9\-]{36}$/', $chunkid)) {
throw new UploadException(__('Invalid parameters'));
}
$iterator = new \GlobIterator($this->chunkDir . DS . $chunkid . '-*', FilesystemIterator::KEY_AS_FILENAME); $iterator = new \GlobIterator($this->chunkDir . DS . $chunkid . '-*', FilesystemIterator::KEY_AS_FILENAME);
$array = iterator_to_array($iterator); $array = iterator_to_array($iterator);
foreach ($array as $index => &$item) { foreach ($array as $index => &$item) {
@ -190,6 +194,10 @@ class Upload
*/ */
public function merge($chunkid, $chunkcount, $filename) public function merge($chunkid, $chunkcount, $filename)
{ {
if (!preg_match('/^[a-z0-9\-]{36}$/', $chunkid)) {
throw new UploadException(__('Invalid parameters'));
}
$filePath = $this->chunkDir . DS . $chunkid; $filePath = $this->chunkDir . DS . $chunkid;
$completed = true; $completed = true;
@ -229,6 +237,8 @@ class Upload
} }
@fclose($destFile); @fclose($destFile);
$attachment = null;
try {
$file = new File($uploadPath); $file = new File($uploadPath);
$info = [ $info = [
'name' => $filename, 'name' => $filename,
@ -249,7 +259,12 @@ class Upload
//允许大文件 //允许大文件
$this->config['maxsize'] = "1024G"; $this->config['maxsize'] = "1024G";
return $this->upload(); $attachment = $this->upload();
} catch (\Exception $e) {
@unlink($destFile);
throw new UploadException($e->getMessage());
}
return $attachment;
} }
/** /**
@ -263,6 +278,10 @@ class Upload
throw new UploadException(__('Uploaded file format is limited')); throw new UploadException(__('Uploaded file format is limited'));
} }
if (!preg_match('/^[a-z0-9\-]{36}$/', $chunkid)) {
throw new UploadException(__('Invalid parameters'));
}
$destDir = RUNTIME_PATH . 'chunks'; $destDir = RUNTIME_PATH . 'chunks';
$fileName = $chunkid . "-" . $chunkindex . '.part'; $fileName = $chunkid . "-" . $chunkindex . '.part';
$destFile = $destDir . DS . $fileName; $destFile = $destDir . DS . $fileName;