Skip to content

Commit 12ddcf9

Browse files
committed
Fix the handling of EXIF data
1 parent 9db9f76 commit 12ddcf9

File tree

7 files changed

+52
-7
lines changed

7 files changed

+52
-7
lines changed

ts/WoltLabSuite/Core/Api/Files/Upload.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export async function upload(
1919

2020
let exifData: string | null = null;
2121
if (exifBytes !== null) {
22-
exifData = new TextDecoder().decode(exifBytes);
22+
exifData = "";
23+
for (let i = 0, length = exifBytes.length; i < length; i++) {
24+
exifData += exifBytes[i].toString(16).padStart(2, "0");
25+
}
2326
}
2427

2528
const payload = {

ts/WoltLabSuite/Core/Component/File/Upload.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,12 @@ function reportError(element: WoltlabCoreFileUploadElement, file: File | null, m
302302
async function getExifBytes(file: File): Promise<Exif | null> {
303303
if (file.type === "image/jpeg") {
304304
try {
305-
return await getExifBytesFromJpeg(file);
305+
const bytes = await getExifBytesFromJpeg(file);
306+
307+
// ExifUtil returns the entire section but we only need the app data.
308+
// Removing the first 10 bytes drops the 0xFF 0xE1 marker followed by two
309+
// bytes for the length and then 6 bytes for the "Exif\x00\x00" header.
310+
return bytes.slice(10);
306311
} catch {
307312
return null;
308313
}

wcfsetup/install/files/js/WoltLabSuite/Core/Api/Files/Upload.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/WoltLabSuite/Core/Component/File/Upload.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ public static function createFromExistingFile(
150150
if ($exifData === null) {
151151
$exifData = ExifUtil::getExifData($pathname);
152152

153+
// Remove the `FILE` and `COMPUTED` section because those contain
154+
// garbled data anyway and we do not need them in the first place.
155+
unset($exifData['FILE'], $exifData['COMPUTED']);
156+
157+
// We can also discard the `THUMBNAIL` section because it is a
158+
// pointless feature and we’re not extracting it either.
159+
unset($exifData['THUMBNAIL']);
160+
153161
if ($exifData === []) {
154162
$exifData = null;
155163
}

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ private function createTemporaryFile(PostUploadParameters $parameters, int $numb
7676
$identifier = \bin2hex(\random_bytes(20));
7777
$objectType = FileProcessor::getInstance()->getObjectType($parameters->objectType);
7878

79-
$exifData = $this->parseExifData($parameters->exifData);
79+
$exifBytes = null;
80+
if ($parameters->exifData !== null) {
81+
$exifBytes = \hex2bin($parameters->exifData);
82+
}
83+
84+
$exifData = $this->parseExifData($exifBytes);
8085
if ($exifData !== null) {
8186
$exifData = JSON::encode($exifData);
8287
}
@@ -104,7 +109,24 @@ private function parseExifData(?string $exifData): array|null
104109
return null;
105110
}
106111

107-
return Exif::forBytes(0, $exifData)->getParsedExif();
112+
$data = Exif::forBytes(0, $exifData)->getParsedExif();
113+
if ($data === null) {
114+
return null;
115+
}
116+
117+
// Remove the `FILE` and `COMPUTED` section because those contain
118+
// garbled data anyway and we do not need them in the first place.
119+
unset($data['FILE'], $data['COMPUTED']);
120+
121+
// We can also discard the `THUMBNAIL` section because it is a
122+
// pointless feature and we’re not extracting it either.
123+
unset($data['THUMBNAIL']);
124+
125+
if ($data === []) {
126+
return null;
127+
}
128+
129+
return $data;
108130
}
109131
}
110132

wcfsetup/install/files/style/ui/dialog.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294
min-width: 500px;
295295
overflow: hidden;
296296
padding: 0;
297-
position: relative;
297+
position: fixed;
298298
}
299299

300300
.dialog:not([open]) {

0 commit comments

Comments
 (0)