Discussion:
Wordpress seems to serialize image_meta of a featured image incorrectly
Jeff Tchang
2014-03-08 00:52:49 UTC
Permalink
Noticing some odd behavior when I upload an image with meta information.
One of the fields has "© 2013".

When it is serialized to the database I see:

s:7:"© 2013";

When I do this in vanilla php:

$a = chr(169) . " 2013";
echo serialize($a);

I get

s:6:"© 2013";

which seems like the correct serialization. Has anyone run into this before?
Justas Butkus
2014-03-08 01:11:12 UTC
Permalink
Actually just the first case is correct, where length is set to 7 bytes,
because copyright symbol (©) takes up two bytes.
While it's encoded in HTML as "©" it's not necessarily copyright
symbol at 169th position in ASCII table (what `chr` returns).

So second encoding is incorrect and if you try to paste it into some PHP
console you may randomly get an error "PHP Notice: unserialize(): Error
at offset 11 of 14 bytes" in some cases, while first example should
unserialize without any errors.
--
Regards,
Justas
Post by Jeff Tchang
Noticing some odd behavior when I upload an image with meta information.
One of the fields has "© 2013".
s:7:"© 2013";
$a = chr(169) . " 2013";
echo serialize($a);
I get
s:6:"© 2013";
which seems like the correct serialization. Has anyone run into this before?
Otto
2014-03-08 07:00:53 UTC
Permalink
Post by Jeff Tchang
Noticing some odd behavior when I upload an image with meta information.
One of the fields has "© 2013".
s:7:"© 2013";
$a = chr(169) . " 2013";
echo serialize($a);
I get
s:6:"© 2013";
which seems like the correct serialization. Has anyone run into this before?
You're comparing different character sets.

In ASCII, the copyright symbol is the character with code 0xA9.

In UTF-8, the copyright symbol is the character with code 0xC2 0xA9.

That extra byte is relevant to the serialization that you're seeing.

-Otto

Loading...