stevebauman/purify

Issue with Unserialization in CacheDefinitionCache after latest commit

Closed this issue · 1 comments

After upgrading this package we get

unserialize(): Error at offset 0 of 13774 bytes {"exception":"[object] (ErrorException(code: 0): unserialize(): Error at offset 0 of 13774 bytes at /srv/production/vendor/stevebauman/purify/src/Cache/CacheDefinitionCache.php:188)

Line 188 corresponds to return unserialize($encoded);

The introduction of base64 encoding in encode() and decode() in 6.1.2 is likely causing compatibility issues with previously cached data.

Possible solution suggested by AI (not tested in any way):

protected function decode($def)
{
    // First, try to base64 decode and then unserialize.
    if ($encoded = base64_decode($def, true)) {
        $decoded = @unserialize($encoded);
        if ($decoded !== false || $encoded === 'b:0;') {
            return $decoded;
        }
    }

    // Fallback to direct unserialization for backward compatibility.
    return @unserialize($def);
}

Thanks for the report @Jon78! This is fixed in v6.1.3 (35e262b).