OllieJones / sqlite-object-cache

A WordPress persistent object cache for the rest of us.
GNU General Public License v2.0
24 stars 4 forks source link

php config change while cache is activated can corrupt a site. #12

Closed OllieJones closed 1 year ago

OllieJones commented 1 year ago

Steps to totally mess up a site.

  1. install and activate this plugin.
  2. use the site for a while, priming the cache with lots of stuff.
  3. change the php configuration to either remove, or install, the igbinary extension.
  4. try to use the site.
  5. Observe bizarre garbage.

Why does this happen? Because the plugin uses function_exists( 'igbinary_serialize' ) to know whether the stuff already in the cache was serialized with igbinary (which is more space- and time- efficient than the ordinary php serialize() function.

Serializing with one and deserializing with the other (a) doesn't cause an error condition!!! and (b) generates garbage cache entries, then kicked back to WordPress. Which chokes.

Workaround: don't do that.

Fix: tag the cache entries by how they were serialized. Deserialize them the same way.

Fix: put something in the database (maybe an extra one row table) with the how-serialized tag. Blow up the cache and start over if there's a mismatch.

OllieJones commented 1 year ago

Now, if no igbinary is available, we include -a in the .sqlite filename.