Created
August 14, 2012 23:34
-
-
Save danielbeardsley/3353895 to your computer and use it in GitHub Desktop.
PHP Bug in recursive unserialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.out | |
a.ser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
class A { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
class B { | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
php serialize_autoload.php > before.out | |
php unserialize_autoload.php > after.out | |
echo "Original ==========" | |
cat before.out | |
echo | |
echo "Unserialized ======" | |
cat after.out | |
echo | |
echo "Diff ==============" | |
(diff -a before.out after.out && echo "Passed, no differences") || | |
echo "FAILED ============" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require "setup.php"; | |
$a = new A(); | |
$b = new B(); | |
$c = new B(); | |
$a->b = $b; | |
$a->b1 = $b; | |
$a->c = $c; | |
$a->c1 = $c; | |
var_dump($a); | |
file_put_contents('a.ser', serialize($a)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function __autoload($name) | |
{ | |
echo "in autoload: $name\n"; | |
// This call causes the bug | |
unserialize('i:4;'); | |
require "$name.php"; | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'setup.php'; | |
var_dump(unserialize(file_get_contents("a.ser"))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And it got fixed here: php/php-src@0b23da1
This bug is fixed as of php 5.4.7