8000 [Cache] Hash using B64+MD5 in FilesystemAdapter by nicolas-grekas · Pull Request #18085 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Cache] Hash using B64+MD5 in FilesystemAdapter #18085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2016

Conversation

nicolas-grekas
Copy link
Member
Q A
Branch master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets -
License MIT
Doc PR -

Using MD5+B64 is good enough to avoid any hash collision, even on case-insensitive filesystems.
On Windows where the total path length is limited, this saves 44 chars worth.
Even if collisions are extremely unlikely, they are detected by adding then comparing the raw key to saved payloads. This also has the added benefit of easing debugging/grepping the cached items on the filesystem.


return $this->directory.$hash[0].DIRECTORY_SEPARATOR.$hash[1].DIRECTORY_SEPARATOR.$hash;
return $this->directory.$hash[0].DIRECTORY_SEPARATOR.$hash[1].DIRECTORY_SEPARATOR.substr($hash, 2, -2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why -2?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because these are padding = added by for b64

@fabpot
Copy link
Member
fabpot commented Mar 10, 2016

Thank you @nicolas-grekas.

@fabpot fabpot merged commit e96bb10 into symfony:master Mar 10, 2016
fabpot added a commit that referenced this pull request Mar 10, 2016
…-grekas)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[Cache] Hash using B64+MD5 in FilesystemAdapter

| Q             | A
| ------------- | ---
| Branch        | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Using MD5+B64 is good enough to avoid any hash collision, even on case-insensitive filesystems.
On Windows where the total path length is limited, this saves 44 chars worth.
Even if collisions are extremely unlikely, they are detected by adding then comparing the raw key to saved payloads. This also has the added benefit of easing debugging/grepping the cached items on the filesystem.

Commits
-------

e96bb10 [Cache] Hash using B64+MD5 in FilesystemAdapter
@nicolas-grekas nicolas-grekas deleted the cache-fs branch March 11, 2016 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0