From cb90261309c6a48b166dbd5622443df1321e05aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 12 Jul 2024 00:00:44 +0200 Subject: [PATCH] Update random_bytes length in filename and prefix generation The size of the random byte string used in the generateFilename method of StoredObjectVersion has been reduced from 16 to 8. Conversely, the size of the random byte string used in the generatePrefix method of StoredObject has been increased from 8 to 32. The naming generation fit better with the usage, as 16bytes are generated for each file (more version), and less for the version. --- src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php | 2 +- src/Bundle/ChillDocStoreBundle/Entity/StoredObjectVersion.php | 2 +- .../ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php b/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php index f37829a26..4fec9f6ca 100644 --- a/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php +++ b/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php @@ -354,7 +354,7 @@ class StoredObject implements Document, TrackCreationInterface public static function generatePrefix(): string { try { - return base_convert(bin2hex(random_bytes(8)), 16, 36); + return base_convert(bin2hex(random_bytes(32)), 16, 36); } catch (RandomException $e) { return uniqid(more_entropy: true); } diff --git a/src/Bundle/ChillDocStoreBundle/Entity/StoredObjectVersion.php b/src/Bundle/ChillDocStoreBundle/Entity/StoredObjectVersion.php index c280b30a3..2b8852513 100644 --- a/src/Bundle/ChillDocStoreBundle/Entity/StoredObjectVersion.php +++ b/src/Bundle/ChillDocStoreBundle/Entity/StoredObjectVersion.php @@ -82,7 +82,7 @@ class StoredObjectVersion implements TrackCreationInterface public static function generateFilename(StoredObjectVersion $storedObjectVersion): string { try { - $suffix = base_convert(bin2hex(random_bytes(16)), 16, 36); + $suffix = base_convert(bin2hex(random_bytes(8)), 16, 36); } catch (RandomException $e) { $suffix = uniqid(more_entropy: true); } diff --git a/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php b/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php index 574fee75b..639133976 100644 --- a/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php +++ b/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php @@ -104,7 +104,7 @@ final readonly class ChillDocumentManager implements DocumentManagerInterface throw new \Error('Unknown mimetype for stored document.'); } - return sprintf('%s.%s', $document->getFilename(), reset($exts)); + return sprintf('%s.%s', $document->getPrefix(), reset($exts)); } /**