Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit 612cb6d

Browse files
committed
Check if file storage is successful
1 parent 1be37b8 commit 612cb6d

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/com/carlgo11/tempfiles/DataStorage.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ public static function deleteOldFiles() {
8585
* @param string $id The ID for the file.
8686
* @param string $password Description
8787
* @return mixed Returns the downloaded and decrypted file (object) if successfully downloaded and decrypted, otherwise NULL (boolean).
88-
* @since 2.0
88+
* @throws Exception
8989
* @since 2.3 Add support for AEAD cipher modes.
9090
* @global array $conf Configuration variables.
9191
* @global object $mysql_connection MySQL connection.
92+
* @since 2.0
9293
*/
9394
public static function getFile(string $id, string $password) {
9495
global $conf;
@@ -108,6 +109,7 @@ public static function getFile(string $id, string $password) {
108109

109110
if ($enc_content !== NULL) {
110111
$metadata_string = Encryption::decrypt($enc_filedata, $password, $iv[2], $iv[3]);
112+
if($metadata_string === FALSE) throw new Exception("Unable to decrypt file metadata.");
111113

112114
/** @var array $metadata_array
113115
* Array containing the following: [name, size, type, deletionPassword, views_array[ 0 => currentViews, 1 => maxViews]]

src/com/carlgo11/tempfiles/File.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
namespace com\carlgo11\tempfiles;
4+
45
class File
56
{
67

@@ -85,7 +86,7 @@ public function getContent() {
8586
* @return boolean Returns TRUE if the action was successfully executed, otherwise FALSE.
8687
* @since 2.2
8788
*/
88-
public function setContent($content) {
89+
public function setContent(string $content) {
8990
return ($this->_content = $content) === $content;
9091
}
9192

src/com/carlgo11/tempfiles/api/Upload.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ function __construct(string $method) {
5151
if ($password !== NULL) {
5252
if ($fileContent['error'] === 0) {
5353
$file->setContent(file_get_contents($fileContent['tmp_name']));
54-
if (!($upload = DataStorage::uploadFile($file, $password))) {
54+
if (!($upload = DataStorage::uploadFile($file, $password)))
5555
throw new Exception("Connection to our database failed.");
56-
}
56+
if (!DataStorage::getFile($file->getID(), $password) instanceof File)
57+
throw new Exception("Unable to verify file integrity.");
5758
} else {
5859
throw new InvalidArgumentException("Upload failed. Either the file is larger than it's supposed to be or the upload was interrupted.");
5960
}

0 commit comments

Comments
 (0)