Fix storage of binary data for array and object types #219

Closed
wants to merge 3 commits into
from

Projects

None yet

5 participants

serialize() returns binary data (NUL bytes) and not all platforms
handle that in CLOB fields (e.g. PostgreSQL).

This change uses base64 encoding to work around that, and transparently
reads (old) non-base64 data as well.

Fixes DBAL-368

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DBAL-369

@stof stof and 1 other commented on an outdated diff Oct 19, 2012
lib/Doctrine/DBAL/Types/ArrayType.php
@@ -45,7 +45,12 @@ public function convertToPHPValue($value, \Doctrine\DBAL\Platforms\AbstractPlatf
}
$value = (is_resource($value)) ? stream_get_contents($value) : $value;
- $val = unserialize($value);
+ // check for plain vs base64 encoded serialized data
+ if (strpos($value, 'a:') === 0 ||strpos($value, 'b:') === 0) {
+ $val = unserialize($value);
+ } else {
+ $val = unserialize(base64_decode($value));
+ }
if ($val === false && $value != 'b:0;') {
stof
stof Oct 19, 2012 Member

this check will not work properly anymore as $value will be encoded

@Baachi Baachi and 1 other commented on an outdated diff Oct 19, 2012
lib/Doctrine/DBAL/Types/ArrayType.php
@@ -45,7 +45,12 @@ public function convertToPHPValue($value, \Doctrine\DBAL\Platforms\AbstractPlatf
}
$value = (is_resource($value)) ? stream_get_contents($value) : $value;
- $val = unserialize($value);
+ // check for plain vs base64 encoded serialized data
+ if (strpos($value, 'a:') === 0 ||strpos($value, 'b:') === 0) {
Baachi
Baachi Oct 19, 2012

Why not simply

<?php
if (false !== strpos($value, ':')) {
    // ...
}

Base64 encoded strings should not contain a :, right?

kdambekalns
kdambekalns Oct 19, 2012

Well, I had a check for { first, but wanted to make it as explicit as possible. I'm open for "as simple as possible" as well. :)

kdambekalns
kdambekalns Oct 19, 2012

So I check for : at the second position now.

kdambekalns added some commits Oct 19, 2012
@kdambekalns kdambekalns Fix storage of binary data for array and object types
serialize() returns binary data (NUL bytes) and not all platforms
handle that in CLOB fields (e.g. PostgreSQL).

This change uses base64 encoding to work around that, and transparently
reads (old) non-base64 data as well.

Fixes DBAL-368
f92f643
@kdambekalns kdambekalns Fix boolean handling with base64 encoded data 1c953c6
@kdambekalns kdambekalns Fix null handling with base64 encoded data fc3086f
Owner

@kdambekalns I need two new types for this, to fix the BC issue. They should be called BinarySafeArrayType and BinarySafeObjectType. Then you can use the Type API to replace the original classes with these ones, if you are running into the problem.

Owner

Closing

@beberlei beberlei closed this Dec 20, 2013
@kdambekalns kdambekalns deleted the unknown repository branch May 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment