Skip to content

Commit 8075fcc

Browse files
committed
refactor(lock): use JSON for file lock metadata
- Replace file lock serialize/unserialize metadata handling with JSON - Keep explicit owner and expiry validation after decoding - Use JSON_THROW_ON_ERROR for encode and decode failures" Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent 9c0e475 commit 8075fcc

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

system/Cache/LockStores/FileLockStore.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private static function readLockData($handle): ?array
146146
}
147147

148148
try {
149-
$data = unserialize($content);
149+
$data = json_decode($content, true, flags: JSON_THROW_ON_ERROR);
150150
} catch (Throwable) {
151151
return null;
152152
}
@@ -169,7 +169,13 @@ private static function writeLockData($handle, string $owner, int $expires): boo
169169
return false;
170170
}
171171

172-
if (fwrite($handle, serialize(['owner' => $owner, 'expires' => $expires])) === false) {
172+
try {
173+
$content = json_encode(['owner' => $owner, 'expires' => $expires], JSON_THROW_ON_ERROR);
174+
} catch (Throwable) {
175+
return false;
176+
}
177+
178+
if (fwrite($handle, $content) === false) {
173179
return false;
174180
}
175181

0 commit comments

Comments
 (0)