Wordpress seems to serialize image_meta of a featured image incorrectly

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Wordpress seems to serialize image_meta of a featured image incorrectly

Jeff Tchang
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?
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Wordpress seems to serialize image_meta of a featured image incorrectly

Justas Butkus
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


2014.03.08 02:52, Jeff Tchang rašė:

> 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?

_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Wordpress seems to serialize image_meta of a featured image incorrectly

Otto-19
In reply to this post by Jeff Tchang
On Fri, Mar 7, 2014 at 6:52 PM, Jeff Tchang <[hidden email]> wrote:

>
> 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?
>


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
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers