From c5ff903455f84bcd65037c43445bca83b5f6a7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Kutn=C3=BD?= Date: Mon, 13 Feb 2017 13:40:14 +0100 Subject: [PATCH] RedisStorage: getUnserializedValue Exception and error When `@unserialize` returns FALSE because of error method `getUnserializedValue` will return NULL and Nette\Caching\Cache::load will regenerate this record. Same for Throwable/Exception thrown from objects implementing \Serializable interface. --- src/Kdyby/Redis/RedisStorage.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Kdyby/Redis/RedisStorage.php b/src/Kdyby/Redis/RedisStorage.php index a905e2f..2e74119 100644 --- a/src/Kdyby/Redis/RedisStorage.php +++ b/src/Kdyby/Redis/RedisStorage.php @@ -379,8 +379,18 @@ private static function getUnserializedValue($stored) if (empty($stored[0][self::META_SERIALIZED])) { return $stored[1]; - } else { - return @unserialize($stored[1]); // intentionally @ + } + try { + $value = @unserialize($stored[1]); // intentionally @ + if ($value === FALSE && $stored[1] !== serialize(FALSE)) { + return NULL; + } + + return $value; + } catch (\Throwable $e) { + return NULL; + } catch (\Exception $e) { + return NULL; } }