xref: /PHP-8.1/ext/session/tests/bug72562.phpt (revision b5a14e6c)
1--TEST--
2Bug #72562: Use After Free in unserialize() with Unexpected Session Deserialization
3--EXTENSIONS--
4session
5--SKIPIF--
6<?php include('skipif.inc'); ?>
7--FILE--
8<?php
9
10ini_set('session.serialize_handler', 'php_binary');
11session_start();
12$sess = "\x1xi:1;\x2y";
13session_decode($sess);
14$uns_1 = '{';
15$out_1[] = unserialize($uns_1);
16unset($out_1);
17$fakezval = ptr2str(1122334455);
18$fakezval .= ptr2str(0);
19$fakezval .= "\x00\x00\x00\x00";
20$fakezval .= "\x01";
21$fakezval .= "\x00";
22$fakezval .= "\x00\x00";
23for ($i = 0; $i < 5; $i++) {
24  $v[$i] = $fakezval.$i;
25}
26$uns_2 = 'R:2;';
27$out_2 = unserialize($uns_2);
28var_dump($out_2);
29
30function ptr2str($ptr)
31{
32    $out = '';
33    for ($i = 0; $i < 8; $i++) {
34        $out .= chr($ptr & 0xff);
35        $ptr >>= 8;
36    }
37    return $out;
38}
39?>
40--EXPECTF--
41Warning: session_decode(): Failed to decode session object. Session has been destroyed in %s%ebug72562.php on line %d
42
43Notice: unserialize(): Error at offset 0 of 1 bytes in %s%ebug72562.php on line %d
44
45Notice: unserialize(): Error at offset 4 of 4 bytes in %s%ebug72562.php on line %d
46bool(false)
47