Skip to content

Commit

Permalink
Merge pull request #2284 from nextcloud/backport/2280/stable28
Browse files Browse the repository at this point in the history
[stable28] Filter out large EXIF entries
  • Loading branch information
artonge authored Feb 1, 2024
2 parents 877a1aa + 9ca712b commit 1c43e98
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/Listener/ExifMetadataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ public function handle(Event $event): void {
}

if ($rawExifData && array_key_exists('EXIF', $rawExifData)) {
$event->getMetadata()->setArray('photos-exif', $this->sanitizeEntries($rawExifData['EXIF']));
$event->getMetadata()->setArray('photos-exif', $this->sanitizeEntries($rawExifData['EXIF'], $node));
}

if ($rawExifData && array_key_exists('IFD0', $rawExifData)) {
$event->getMetadata()->setArray('photos-ifd0', $this->sanitizeEntries($rawExifData['IFD0']));
$event->getMetadata()->setArray('photos-ifd0', $this->sanitizeEntries($rawExifData['IFD0'], $node));
}

if (
Expand Down Expand Up @@ -154,7 +154,7 @@ private function parseGPSData(string $rawData): float {
*
* @param array<string, string> $data
*/
private function sanitizeEntries(array $data): array {
private function sanitizeEntries(array $data, File $node): array {
$cleanData = [];

foreach ($data as $key => $value) {
Expand All @@ -169,7 +169,19 @@ private function sanitizeEntries(array $data): array {
$key = preg_replace('/[^a-zA-Z]/', '_', $key);
}

$cleanData[$key] = $value;
// Arbitrary limit to filter out large EXIF entries.
if (is_string($value) && strlen($value) > 1000) {
$this->logger->info(
"EXIF entry ignored as it is too large",
[
'key' => $key,
'value' => $value,
'fileId' => $node->getId(),
]
);
} else {
$cleanData[$key] = $value;
}
}

return $cleanData;
Expand Down

0 comments on commit 1c43e98

Please sign in to comment.