{"action":"created","comment":{"url":"https://api.github.com/repos/phpseclib/phpseclib/pulls/comments/52848598","id":52848598,"diff_hunk":"@@ -260,6 +260,44 @@ function crypt_random_string($length)\n     }\n }\n \n+if (!function_exists('phpseclib_safe_serialize')) {\n+    /**\n+     * Safely serialize variables\n+     *\n+     * If a class has a private __sleep() method it'll give a fatal error on PHP 5.2 and earlier.\n+     * PHP 5.3 will emit a warning.\n+     *\n+     * @param mixed $arr\n+     * @param array $refs optional\n+     * @access public\n+     */\n+    function phpseclib_safe_serialize($arr, $refs = array())\n+    {\n+        if (is_object($arr)) {\n+            return '';\n+        }\n+        if (!is_array($arr)) {\n+            return serialize($arr);\n+        }\n+        $safearr = array();\n+        foreach (array_keys($arr) as $key) {\n+            if (is_object($arr[$key])) {\n+                continue;\n+            }\n+            // without this recursive arrays (eg. $a = []; $a[] = &$a;) would result in an\n+            // \"Allowed memory size of ... bytes exhausted\" Fatal error\n+            foreach ($refs as $ref) {\n+                if ($ref === $arr[$key]) {","path":"phpseclib/Crypt/Random.php","position":52,"original_position":52,"commit_id":"dfb256a4d8c212e49d403cbd10829e6519823046","original_commit_id":"dfb256a4d8c212e49d403cbd10829e6519823046","user":{"login":"Joey3000","id":3662335,"avatar_url":"https://avatars.githubusercontent.com/u/3662335?v=3","gravatar_id":"","url":"https://api.github.com/users/Joey3000","html_url":"https://github.com/Joey3000","followers_url":"https://api.github.com/users/Joey3000/followers","following_url":"https://api.github.com/users/Joey3000/following{/other_user}","gists_url":"https://api.github.com/users/Joey3000/gists{/gist_id}","starred_url":"https://api.github.com/users/Joey3000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Joey3000/subscriptions","organizations_url":"https://api.github.com/users/Joey3000/orgs","repos_url":"https://api.github.com/users/Joey3000/repos","events_url":"https://api.github.com/users/Joey3000/events{/privacy}","received_events_url":"https://api.github.com/users/Joey3000/received_events","type":"User","site_admin":false},"body":"Thanks!\r\n\r\n> I don't think `$key !== '__phpseclib_marker' &&` is necessary\r\n\r\n* Without it, each '__phpseclib_marker' key is also serialized. E.g., the test variables in https://github.com/phpseclib/phpseclib/pull/934/files#r52842344 above result in the following output (on PHP 7.0.3):\r\n\r\n  ```\r\n  a:9:{s:4:\"_GET\";s:36:\"a:1:{s:18:\"__phpseclib_marker\";b:1;}\";s:5:\"_POST\";s:36:\"a:1:\r\n  {s:18:\"__phpseclib_marker\";b:1;}\";s:7:\"_COOKIE\";s:36:\"a:1:\r\n  {s:18:\"__phpseclib_marker\";b:1;}\";s:6:\"_FILES\";s:36:\"a:1:\r\n  {s:18:\"__phpseclib_marker\";b:1;}\";s:1:\"a\";s:60:\"a:2:\r\n  {s:4:\"key1\";s:6:\"value1\";s:18:\"__phpseclib_marker\";b:1;}\";s:1:\"b\";s:108:\"a:2:{i:0;s:60:\"a:2:\r\n  {s:4:\"key1\";s:6:\"value1\";s:18:\"__phpseclib_marker\";b:1;}\";s:18:\"__phpseclib_marker\";b:1;}\r\n  \";s:1:\"c\";s:157:\"a:2:{i:0;s:108:\"a:2:{i:0;s:60:\"a:2:\r\n  {s:4:\"key1\";s:6:\"value1\";s:18:\"__phpseclib_marker\";b:1;}\";s:18:\"__phpseclib_marker\";b:1;}\r\n  \";s:18:\"__phpseclib_marker\";b:1;}\";s:1:\"z\";s:84:\"a:2:{i:0;s:36:\"a:1:\r\n  {s:18:\"__phpseclib_marker\";b:1;}\";s:18:\"__phpseclib_marker\";b:1;}\";s:18:\"__phpseclib_marker\";b:1;}\r\n  ```\r\n\r\n  As opposed to the following otherwise:\r\n\r\n  ```\r\n  a:8:{s:4:\"_GET\";s:6:\"a:0:{}\";s:5:\"_POST\";s:6:\"a:0:{}\";s:7:\"_COOKIE\";s:6:\"a:0:{}\";s:6:\"_FILES\";s:6:\"a:0:\r\n  {}\";s:1:\"a\";s:30:\"a:1:{s:4:\"key1\";s:6:\"value1\";}\";s:1:\"b\";s:48:\"a:1:{i:0;s:30:\"a:1:\r\n  {s:4:\"key1\";s:6:\"value1\";}\";}\";s:1:\"c\";s:66:\"a:1:{i:0;s:48:\"a:1:{i:0;s:30:\"a:1:\r\n  {s:4:\"key1\";s:6:\"value1\";}\";}\";}\";s:1:\"z\";s:23:\"a:1:{i:0;s:6:\"a:0:{}\";}\";}\r\n  ```\r\n\r\n  So, roughly the double RAM consumption on that non-representative test. (And a similar proportion on PHP 4.4.9.) I don't know how much impact that has in a typical PHP environment though, with respect to the number of existing global variables containing arrays (don't need to be circular).\r\n\r\n* Also, the comment on the following line would need to be removed then as well: https://github.com/terrafrost/phpseclib/pull/6/files#diff-b08ee4e00815fdb38838fb5016bd2ee4R285.","created_at":"2016-02-14T20:59:18Z","updated_at":"2016-02-14T20:59:18Z","html_url":"https://github.com/phpseclib/phpseclib/pull/934#discussion_r52848598","pull_request_url":"https://api.github.com/repos/phpseclib/phpseclib/pulls/934","_links":{"self":{"href":"https://api.github.com/repos/phpseclib/phpseclib/pulls/comments/52848598"},"html":{"href":"https://github.com/phpseclib/phpseclib/pull/934#discussion_r52848598"},"pull_request":{"href":"https://api.github.com/repos/phpseclib/phpseclib/pulls/934"}}},"pull_request":{"url":"https://api.github.com/repos/phpseclib/phpseclib/pulls/934","id":57116107,"html_url":"https://github.com/phpseclib/phpseclib/pull/934","diff_url":"https://github.com/phpseclib/phpseclib/pull/934.diff","patch_url":"https://github.com/phpseclib/phpseclib/pull/934.patch","issue_url":"https://api.github.com/repos/phpseclib/phpseclib/issues/934","number":934,"state":"open","locked":false,"title":"Random: fix for issues with serialize()","user":{"login":"terrafrost","id":214474,"avatar_url":"https://avatars.githubusercontent.com/u/214474?v=3","gravatar_id":"","url":"https://api.github.com/users/terrafrost","html_url":"https://github.com/terrafrost","followers_url":"https://api.github.com/users/terrafrost/followers","following_url":"https://api.github.com/users/terrafrost/following{/other_user}","gists_url":"https://api.github.com/users/terrafrost/gists{/gist_id}","starred_url":"https://api.github.com/users/terrafrost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terrafrost/subscriptions","organizations_url":"https://api.github.com/users/terrafrost/orgs","repos_url":"https://api.github.com/users/terrafrost/repos","events_url":"https://api.github.com/users/terrafrost/events{/privacy}","received_events_url":"https://api.github.com/users/terrafrost/received_events","type":"User","site_admin":false},"body":"Fixes #932.\r\n\r\n(latest branch: https://github.com/terrafrost/phpseclib/tree/random-serialize-3)","created_at":"2016-01-25T19:15:26Z","updated_at":"2016-02-14T20:59:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c6f216380efd5b926312eb80422cdfca5052da46","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/phpseclib/phpseclib/pulls/934/commits","review_comments_url":"https://api.github.com/repos/phpseclib/phpseclib/pulls/934/comments","review_comment_url":"https://api.github.com/repos/phpseclib/phpseclib/pulls/comments{/number}","comments_url":"https://api.github.com/repos/phpseclib/phpseclib/issues/934/comments","statuses_url":"https://api.github.com/repos/phpseclib/phpseclib/statuses/dfb256a4d8c212e49d403cbd10829e6519823046","head":{"label":"terrafrost:random-serialize","ref":"random-serialize","sha":"dfb256a4d8c212e49d403cbd10829e6519823046","user":{"login":"terrafrost","id":214474,"avatar_url":"https://avatars.githubusercontent.com/u/214474?v=3","gravatar_id":"","url":"https://api.github.com/users/terrafrost","html_url":"https://github.com/terrafrost","followers_url":"https://api.github.com/users/terrafrost/followers","following_url":"https://api.github.com/users/terrafrost/following{/other_user}","gists_url":"https://api.github.com/users/terrafrost/gists{/gist_id}","starred_url":"https://api.github.com/users/terrafrost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terrafrost/subscriptions","organizations_url":"https://api.github.com/users/terrafrost/orgs","repos_url":"https://api.github.com/users/terrafrost/repos","events_url":"https://api.github.com/users/terrafrost/events{/privacy}","received_events_url":"https://api.github.com/users/terrafrost/received_events","type":"User","site_admin":false},"repo":{"id":4767988,"name":"phpseclib","full_name":"terrafrost/phpseclib","owner":{"login":"terrafrost","id":214474,"avatar_url":"https://avatars.githubusercontent.com/u/214474?v=3","gravatar_id":"","url":"https://api.github.com/users/terrafrost","html_url":"https://github.com/terrafrost","followers_url":"https://api.github.com/users/terrafrost/followers","following_url":"https://api.github.com/users/terrafrost/following{/other_user}","gists_url":"https://api.github.com/users/terrafrost/gists{/gist_id}","starred_url":"https://api.github.com/users/terrafrost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terrafrost/subscriptions","organizations_url":"https://api.github.com/users/terrafrost/orgs","repos_url":"https://api.github.com/users/terrafrost/repos","events_url":"https://api.github.com/users/terrafrost/events{/privacy}","received_events_url":"https://api.github.com/users/terrafrost/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/terrafrost/phpseclib","description":"PHP Secure Communications Library","fork":true,"url":"https://api.github.com/repos/terrafrost/phpseclib","forks_url":"https://api.github.com/repos/terrafrost/phpseclib/forks","keys_url":"https://api.github.com/repos/terrafrost/phpseclib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/terrafrost/phpseclib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/terrafrost/phpseclib/teams","hooks_url":"https://api.github.com/repos/terrafrost/phpseclib/hooks","issue_events_url":"https://api.github.com/repos/terrafrost/phpseclib/issues/events{/number}","events_url":"https://api.github.com/repos/terrafrost/phpseclib/events","assignees_url":"https://api.github.com/repos/terrafrost/phpseclib/assignees{/user}","branches_url":"https://api.github.com/repos/terrafrost/phpseclib/branches{/branch}","tags_url":"https://api.github.com/repos/terrafrost/phpseclib/tags","blobs_url":"https://api.github.com/repos/terrafrost/phpseclib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/terrafrost/phpseclib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/terrafrost/phpseclib/git/refs{/sha}","trees_url":"https://api.github.com/repos/terrafrost/phpseclib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/terrafrost/phpseclib/statuses/{sha}","languages_url":"https://api.github.com/repos/terrafrost/phpseclib/languages","stargazers_url":"https://api.github.com/repos/terrafrost/phpseclib/stargazers","contributors_url":"https://api.github.com/repos/terrafrost/phpseclib/contributors","subscribers_url":"https://api.github.com/repos/terrafrost/phpseclib/subscribers","subscription_url":"https://api.github.com/repos/terrafrost/phpseclib/subscription","commits_url":"https://api.github.com/repos/terrafrost/phpseclib/commits{/sha}","git_commits_url":"https://api.github.com/repos/terrafrost/phpseclib/git/commits{/sha}","comments_url":"https://api.github.com/repos/terrafrost/phpseclib/comments{/number}","issue_comment_url":"https://api.github.com/repos/terrafrost/phpseclib/issues/comments{/number}","contents_url":"https://api.github.com/repos/terrafrost/phpseclib/contents/{+path}","compare_url":"https://api.github.com/repos/terrafrost/phpseclib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/terrafrost/phpseclib/merges","archive_url":"https://api.github.com/repos/terrafrost/phpseclib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/terrafrost/phpseclib/downloads","issues_url":"https://api.github.com/repos/terrafrost/phpseclib/issues{/number}","pulls_url":"https://api.github.com/repos/terrafrost/phpseclib/pulls{/number}","milestones_url":"https://api.github.com/repos/terrafrost/phpseclib/milestones{/number}","notifications_url":"https://api.github.com/repos/terrafrost/phpseclib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/terrafrost/phpseclib/labels{/name}","releases_url":"https://api.github.com/repos/terrafrost/phpseclib/releases{/id}","deployments_url":"https://api.github.com/repos/terrafrost/phpseclib/deployments","created_at":"2012-06-23T22:07:05Z","updated_at":"2015-12-23T21:00:50Z","pushed_at":"2016-02-14T17:33:55Z","git_url":"git://github.com/terrafrost/phpseclib.git","ssh_url":"git@github.com:terrafrost/phpseclib.git","clone_url":"https://github.com/terrafrost/phpseclib.git","svn_url":"https://github.com/terrafrost/phpseclib","homepage":null,"size":6460,"stargazers_count":4,"watchers_count":4,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":4,"default_branch":"master"}},"base":{"label":"phpseclib:1.0","ref":"1.0","sha":"f60e365be28d9218b4bcdc0ab96ac7e338668f11","user":{"login":"phpseclib","id":1820952,"avatar_url":"https://avatars.githubusercontent.com/u/1820952?v=3","gravatar_id":"","url":"https://api.github.com/users/phpseclib","html_url":"https://github.com/phpseclib","followers_url":"https://api.github.com/users/phpseclib/followers","following_url":"https://api.github.com/users/phpseclib/following{/other_user}","gists_url":"https://api.github.com/users/phpseclib/gists{/gist_id}","starred_url":"https://api.github.com/users/phpseclib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phpseclib/subscriptions","organizations_url":"https://api.github.com/users/phpseclib/orgs","repos_url":"https://api.github.com/users/phpseclib/repos","events_url":"https://api.github.com/users/phpseclib/events{/privacy}","received_events_url":"https://api.github.com/users/phpseclib/received_events","type":"Organization","site_admin":false},"repo":{"id":4565995,"name":"phpseclib","full_name":"phpseclib/phpseclib","owner":{"login":"phpseclib","id":1820952,"avatar_url":"https://avatars.githubusercontent.com/u/1820952?v=3","gravatar_id":"","url":"https://api.github.com/users/phpseclib","html_url":"https://github.com/phpseclib","followers_url":"https://api.github.com/users/phpseclib/followers","following_url":"https://api.github.com/users/phpseclib/following{/other_user}","gists_url":"https://api.github.com/users/phpseclib/gists{/gist_id}","starred_url":"https://api.github.com/users/phpseclib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phpseclib/subscriptions","organizations_url":"https://api.github.com/users/phpseclib/orgs","repos_url":"https://api.github.com/users/phpseclib/repos","events_url":"https://api.github.com/users/phpseclib/events{/privacy}","received_events_url":"https://api.github.com/users/phpseclib/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/phpseclib/phpseclib","description":"PHP Secure Communications Library","fork":false,"url":"https://api.github.com/repos/phpseclib/phpseclib","forks_url":"https://api.github.com/repos/phpseclib/phpseclib/forks","keys_url":"https://api.github.com/repos/phpseclib/phpseclib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/phpseclib/phpseclib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/phpseclib/phpseclib/teams","hooks_url":"https://api.github.com/repos/phpseclib/phpseclib/hooks","issue_events_url":"https://api.github.com/repos/phpseclib/phpseclib/issues/events{/number}","events_url":"https://api.github.com/repos/phpseclib/phpseclib/events","assignees_url":"https://api.github.com/repos/phpseclib/phpseclib/assignees{/user}","branches_url":"https://api.github.com/repos/phpseclib/phpseclib/branches{/branch}","tags_url":"https://api.github.com/repos/phpseclib/phpseclib/tags","blobs_url":"https://api.github.com/repos/phpseclib/phpseclib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/phpseclib/phpseclib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/phpseclib/phpseclib/git/refs{/sha}","trees_url":"https://api.github.com/repos/phpseclib/phpseclib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/phpseclib/phpseclib/statuses/{sha}","languages_url":"https://api.github.com/repos/phpseclib/phpseclib/languages","stargazers_url":"https://api.github.com/repos/phpseclib/phpseclib/stargazers","contributors_url":"https://api.github.com/repos/phpseclib/phpseclib/contributors","subscribers_url":"https://api.github.com/repos/phpseclib/phpseclib/subscribers","subscription_url":"https://api.github.com/repos/phpseclib/phpseclib/subscription","commits_url":"https://api.github.com/repos/phpseclib/phpseclib/commits{/sha}","git_commits_url":"https://api.github.com/repos/phpseclib/phpseclib/git/commits{/sha}","comments_url":"https://api.github.com/repos/phpseclib/phpseclib/comments{/number}","issue_comment_url":"https://api.github.com/repos/phpseclib/phpseclib/issues/comments{/number}","contents_url":"https://api.github.com/repos/phpseclib/phpseclib/contents/{+path}","compare_url":"https://api.github.com/repos/phpseclib/phpseclib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/phpseclib/phpseclib/merges","archive_url":"https://api.github.com/repos/phpseclib/phpseclib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/phpseclib/phpseclib/downloads","issues_url":"https://api.github.com/repos/phpseclib/phpseclib/issues{/number}","pulls_url":"https://api.github.com/repos/phpseclib/phpseclib/pulls{/number}","milestones_url":"https://api.github.com/repos/phpseclib/phpseclib/milestones{/number}","notifications_url":"https://api.github.com/repos/phpseclib/phpseclib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/phpseclib/phpseclib/labels{/name}","releases_url":"https://api.github.com/repos/phpseclib/phpseclib/releases{/id}","deployments_url":"https://api.github.com/repos/phpseclib/phpseclib/deployments","created_at":"2012-06-05T21:55:28Z","updated_at":"2016-02-13T08:30:53Z","pushed_at":"2016-02-14T17:33:56Z","git_url":"git://github.com/phpseclib/phpseclib.git","ssh_url":"git@github.com:phpseclib/phpseclib.git","clone_url":"https://github.com/phpseclib/phpseclib.git","svn_url":"https://github.com/phpseclib/phpseclib","homepage":"http://phpseclib.sourceforge.net","size":9062,"stargazers_count":947,"watchers_count":947,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":282,"mirror_url":null,"open_issues_count":105,"forks":282,"open_issues":105,"watchers":947,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/phpseclib/phpseclib/pulls/934"},"html":{"href":"https://github.com/phpseclib/phpseclib/pull/934"},"issue":{"href":"https://api.github.com/repos/phpseclib/phpseclib/issues/934"},"comments":{"href":"https://api.github.com/repos/phpseclib/phpseclib/issues/934/comments"},"review_comments":{"href":"https://api.github.com/repos/phpseclib/phpseclib/pulls/934/comments"},"review_comment":{"href":"https://api.github.com/repos/phpseclib/phpseclib/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/phpseclib/phpseclib/pulls/934/commits"},"statuses":{"href":"https://api.github.com/repos/phpseclib/phpseclib/statuses/dfb256a4d8c212e49d403cbd10829e6519823046"}}}}