By some reasons, if key in user->data is empty, drupal_unpack will end a script unexpectedly... (blank page)

For example

if user->data is...

'a:12:{s:7:"contact";i:1;s:17:"messaging_default";s:6:"simple";s:14:"picture_delete";s:0:"";s:14:"picture_upload";s:0:"";s:5:"block";a:2:{s:10:"phpbbforum";a:1:{i:4;i:1;}s:9:"tagadelic";a:1:{i:3;i:1;}}s:13:"form_build_id";s:37:"form-5845cd29294800377037e3ff12d87ce2";s:21:"profile_schoolwebsite";s:19:"http://nononono.com";s:10:"profile_la";s:8:"VORAPOAP";s:15:"profile_country";s:19:"Antigua and Barbuda";s:22:"profile_school_message";s:8:"VORAPOAP";s:18:"profile_schooltype";s:3:"n/a";s:0:"";s:35:"School msg msg msg 2222222222222222";}'

Notice that the key for the last item in this serialized string is empty.. Unserialize can decode this string as follows

array ( 'contact' => 1, 'messaging_default' => 'simple', 'picture_delete' => '', 'picture_upload' => '', 'block' => array ( 'phpbbforum' => array ( 4 => 1, ), 'tagadelic' => array ( 3 => 1, ), ), 'form_build_id' => 'form-5845cd29294800377037e3ff12d87ce2', 'profile_schoolwebsite' => 'http://nononono.com', 'profile_la' => 'VORAPOAP', 'profile_country' => 'Antigua and Barbuda', 'profile_school_message' => 'VORAPOAP', 'profile_schooltype' => 'n/a', '' => 'School msg msg msg 2222222222222222', )

.. but drupal_unpack will end up in a blank page... (run-time php parse error?)

function drupal_unpack($obj, $field = 'data') {
  if ($obj->$field && $data = unserialize($obj->$field)) {
    foreach ($data as $key => $value) {
      if (!isset($obj->$key)) {
        $obj->$key = $value;
      }
    }
  }
  return $obj;
}

I believe that $obj->$key will cause a blank page if $key is empty string.
Add a line to check this would be nice...

Comments

vorapoap’s picture

I suggest this for the new drupal_unpack version.....

includes/bootstrap.inc

function drupal_unpack($obj, $field = 'data') {
  if ($obj->$field && $data = unserialize($obj->$field)) {
    foreach ($data as $key => $value) {
      if (!empty($key) && !isset($obj->$key)) {
        $obj->$key = $value;
      }
    }
  }
  return $obj;
}
vorapoap’s picture

Version: 6.15 » 6.16

This problem still exists in 6.16

Gerhard Killesreiter’s picture