Skip to content

ViewCache key is insufficiently collision-resistent #1903

@TimWolla

Description

@TimWolla

Tempest version

git 3.x (afe65d3)

PHP version

8.5

Operating system

Linux

Description

CRC-32 as used by the ViewCache in

$cacheKey = (string) crc32($path);

has a 32-bit output size, which means that collisions are expected with a 50% chance at ~65k different inputs. However there are even trivially matching pairs when just looking at English words.

Steps to reproduce

Run env ENVIRONMENT=production php test.php for:

<?php

use Tempest\Core\Tempest;
use Tempest\View\ViewRenderer;

require('vendor/autoload.php');

$container = Tempest::boot(__DIR__, []);

$renderer = $container->get(ViewRenderer::class);

var_dump($renderer->render('petfood'));
var_dump($renderer->render('eisenhower'));

This incorrectly outputs:

string(7) "petfood"
string(7) "petfood"

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions