update_option can't store serialized binary in wp_options.option_value column
|Reported by:||mmaunder||Owned by:|
If a plugin developer tries to use update_option to store an array containing binary data, the array is not deserialized correctly and update_option instead returns the start of the serialized string.
Test script you can use in a plugin:
$test = get_option('mdm', false); error_log(var_export($test, true)); $binOn = true; update_option('mdm', array(md5('asdf', $binOn), md5('qwer', $binOn), md5('sss', $binOn)));
alter table wp_options modify option_value longblob;
Then it works correctly.
Because wp_options currently stores serialized PHP data as longtext instead of longblob, the database receives the full binary data but truncates it when trying to store it as utf8 characters. Making the column binary appears to fix the issue because the database gives PHP back exactly what was inserted.
The obvious answer is: create your own tables if you want to store binary.
But I'm reporting this because I worry that it may have more subtle effects like incorrectly storing I18N chars when serialized.