Skip to content

Commit

Permalink
Workaround for corrupted serialized meta data
Browse files Browse the repository at this point in the history
When database encoding changed from single to multibyte character set
unserialize function fails for data with multibyte characters.

The webmaster should fix this in the database...

We try to get around the error.
  • Loading branch information
oricgn committed Oct 7, 2016
1 parent e8aaa1b commit 1778174
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion include/db/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -1436,9 +1436,23 @@ function phorum_db_get_messages($thread, $page=0, $ignore_mod_perms=FALSE, $writ
foreach ($messages as $id => $message)
{
// Unpack the message meta data.
if (!empty($message['meta'])) {
$fixed_meta = @unserialize($message['meta']);
if ($fixed_meta === false) {
// When database encoding changed from single to multibyte character set
// unserialize function fails for data with multibyte characters.
// The webmaster should fix this in the database...
// We try to get around the error.
$fixed_meta = preg_replace_callback(
'/s:([0-9]+):\"(.*?)\";/',
function ($matches) { return "s:".strlen($matches[2]).':"'.$matches[2].'";'; },
$message['meta']
);
}
}
$messages[$id]['meta'] = empty($message['meta'])
? array()
: unserialize($message['meta']);
: $fixed_meta;

// Collect all involved users.
if ($message['user_id']) {
Expand Down

1 comment on commit 1778174

@glensc
Copy link

@glensc glensc commented on 1778174 Nov 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks php 5.2 compatibility, closures were introduced in PHP 5.3

Please sign in to comment.