Skip to content

Commit 386092a

Browse files
committed
Serialize the EXIF data instead of encoding it as JSON
The parsed data may contain arbitrary binary blobs that cannot be encoded in JSON. See https://www.woltlab.com/community/thread/314636/
1 parent 94bfe3a commit 386092a

File tree

7 files changed

+93
-88
lines changed

7 files changed

+93
-88
lines changed

wcfsetup/install/files/acp/database/update_com.woltlab.wcf_6.2_step1.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
use wcf\system\database\table\column\IntDatabaseTableColumn;
12+
use wcf\system\database\table\column\MediumblobDatabaseTableColumn;
1213
use wcf\system\database\table\column\MediumtextDatabaseTableColumn;
1314
use wcf\system\database\table\column\VarcharDatabaseTableColumn;
1415
use wcf\system\database\table\column\NotNullVarchar255DatabaseTableColumn;
@@ -69,11 +70,11 @@
6970
PartialDatabaseTable::create('wcf1_file')
7071
->columns([
7172
IntDatabaseTableColumn::create('uploadTime'),
72-
MediumtextDatabaseTableColumn::create('exifData'),
73+
MediumblobDatabaseTableColumn::create('exifData'),
7374
]),
7475
PartialDatabaseTable::create('wcf1_file_temporary')
7576
->columns([
76-
MediumtextDatabaseTableColumn::create('exifData'),
77+
MediumblobDatabaseTableColumn::create('exifData'),
7778
]),
7879
PartialDatabaseTable::create('wcf1_menu_item')
7980
->columns([

wcfsetup/install/files/acp/update_com.woltlab.wcf_6.1.0_beta_2_migrateStaticFiles.php

Lines changed: 0 additions & 80 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace wcf\acp;
4+
5+
use wcf\system\package\SplitNodeException;
6+
use wcf\system\WCF;
7+
use wcf\util\JSON;
8+
9+
$sql = "UPDATE wcf1_file_temporary
10+
SET exifData = ?
11+
WHERE identifier = ?";
12+
$updateStatement = WCF::getDB()->prepare($sql);
13+
14+
WCF::getDB()->beginTransaction();
15+
16+
$sql = "SELECT identifier, exifData
17+
FROM wcf1_file_temporary
18+
WHERE exifData LIKE ?
19+
ORDER BY identifier
20+
FOR UPDATE";
21+
$statement = WCF::getDB()->prepare($sql, 50);
22+
$statement->execute(['{"%']);
23+
24+
$replacedData = false;
25+
while ($row = $statement->fetchArray()) {
26+
// This will fail loud but this is only a beta release thus we rather
27+
// catch errors than discarding them silently.
28+
$data = JSON::decode($row['exifData']);
29+
30+
$updateStatement->execute([
31+
\serialize($data),
32+
$row['identifier'],
33+
]);
34+
35+
$replacedData = true;
36+
}
37+
38+
WCF::getDB()->commitTransaction();
39+
40+
if ($replacedData) {
41+
throw new SplitNodeException();
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace wcf\acp;
4+
5+
use wcf\system\package\SplitNodeException;
6+
use wcf\system\WCF;
7+
use wcf\util\JSON;
8+
9+
$sql = "UPDATE wcf1_file
10+
SET exifData = ?
11+
WHERE fileID = ?";
12+
$updateStatement = WCF::getDB()->prepare($sql);
13+
14+
WCF::getDB()->beginTransaction();
15+
16+
$sql = "SELECT fileID, exifData
17+
FROM wcf1_file
18+
WHERE exifData LIKE ?
19+
ORDER BY fileID
20+
FOR UPDATE";
21+
$statement = WCF::getDB()->prepare($sql, 50);
22+
$statement->execute(['{"%']);
23+
24+
$replacedData = false;
25+
while ($row = $statement->fetchArray()) {
26+
// This will fail loud but this is only a beta release thus we rather
27+
// catch errors than discarding them silently.
28+
$data = JSON::decode($row['exifData']);
29+
30+
$updateStatement->execute([
31+
\serialize($data),
32+
$row['fileID'],
33+
]);
34+
35+
$replacedData = true;
36+
}
37+
38+
WCF::getDB()->commitTransaction();
39+
40+
if ($replacedData) {
41+
throw new SplitNodeException();
42+
}

wcfsetup/install/files/lib/data/file/FileEditor.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static function createFromTemporary(FileTemporary $fileTemporary): File
7676

7777
$exifData = $fileTemporary->exifData;
7878
if ($exifData !== null) {
79-
$exifData = JSON::decode($exifData);
79+
$exifData = \unserialize($exifData);
8080
}
8181

8282
$fileSize = $fileTemporary->fileSize;
@@ -115,7 +115,7 @@ public static function createFromTemporary(FileTemporary $fileTemporary): File
115115
'width' => $width,
116116
'height' => $height,
117117
'uploadTime' => \TIME_NOW,
118-
'exifData' => $exifData !== null ? JSON::encode($exifData) : null,
118+
'exifData' => $exifData !== null ? \serialize($exifData) : null,
119119
]]);
120120
$file = $fileAction->executeAction()['returnValues'];
121121
\assert($file instanceof File);
@@ -220,7 +220,7 @@ public static function createFromExistingFile(
220220
'width' => $width,
221221
'height' => $height,
222222
'uploadTime' => $uploadTime,
223-
'exifData' => $exifData !== null ? JSON::encode($exifData) : null,
223+
'exifData' => $exifData !== null ? \serialize($exifData) : null,
224224
]]);
225225
$file = $fileAction->executeAction()['returnValues'];
226226
\assert($file instanceof File);

wcfsetup/install/files/lib/system/endpoint/controller/core/files/PrepareUpload.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private function createTemporaryFile(PostUploadParameters $parameters, int $numb
8686

8787
$exifData = $this->parseExifData($exifBytes);
8888
if ($exifData !== null) {
89-
$exifData = JSON::encode($exifData);
89+
$exifData = \serialize($exifData);
9090
}
9191

9292
$action = new FileTemporaryAction([], 'create', [

wcfsetup/setup/db/install.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ CREATE TABLE wcf1_file (
608608
height INT,
609609
fileHashWebp CHAR(64),
610610
uploadTime INT,
611-
exifData MEDIUMTEXT
611+
exifData MEDIUMBLOB
612612
);
613613

614614
DROP TABLE IF EXISTS wcf1_file_temporary;
@@ -621,7 +621,7 @@ CREATE TABLE wcf1_file_temporary (
621621
objectTypeID INT,
622622
context TEXT,
623623
chunks VARBINARY(255) NOT NULL,
624-
exifData MEDIUMTEXT
624+
exifData MEDIUMBLOB
625625
);
626626

627627
DROP TABLE IF EXISTS wcf1_file_thumbnail;

0 commit comments

Comments
 (0)