fix(serialization): accept non-string stored values in deserializeValue#6
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reported on the horde mailing list: with Memcache configured, IMP dynamic view crashes on the ThemesCache read path:
```
TypeError: Horde\HashTable\Driver\Memcache::deserializeValue(): Argument #1 ($stored) must be of type string, int given, called in .../Driver/Memcache.php on line 99
and defined in .../SerializationTrait.php:57
```
Root cause
`HashTable\Driver\Memcache::getMultiple()` calls `$this->deserializeValue($val)` on every hit, where `$val` is what `MemcacheApi::getItems()` returns after its own `unserialize()` pass (see `MemcacheApi.php:583`).
The value in that slot is not always a string. Any of the following puts a non-prefixed value into the same memcached pool:
`SerializationTrait` already documents the intent to be forgiving ("Legacy data without prefix — treat as raw string", line 65–66), but the `string $stored` type declaration prevents that branch from ever running for non-strings and throws a TypeError instead.
Change
`SerializationTrait::deserializeValue()` now takes `mixed` and passes non-strings through unchanged. String values still go through the `s:`/`p:` prefix protocol; unprefixed strings still fall through to the documented raw-string path.
New unit tests in `test/src/Unit/SerializationTraitTest.php` cover:
Fixes the mailing-list crash without changing behaviour for values written by the modern writer.