{"action":"created","comment":{"url":"https://api.github.com/repos/realm/realm-core/pulls/comments/243602773","pull_request_review_id":187422805,"id":243602773,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0MzYwMjc3Mw==","diff_hunk":"@@ -285,6 +285,42 @@ void Group::remap_and_update_refs(ref_type new_top_ref, size_t new_file_size)\n     update_refs(new_top_ref, old_baseline);\n }\n \n+void Group::validate_top_array(const Array& arr, const SlabAlloc& alloc)\n+{\n+    size_t top_size = arr.size();\n+    ref_type top_ref = arr.get_ref();\n+\n+    switch (top_size) {\n+        // These are the valid sizes\n+        case 3:\n+        case 5:\n+        case 7:\n+        case 9:\n+        case 10: {\n+            ref_type table_names_ref = arr.get_as_ref_or_tagged(0).get_as_ref();\n+            ref_type tables_ref = arr.get_as_ref_or_tagged(1).get_as_ref();\n+            auto logical_file_size = arr.get_as_ref_or_tagged(2).get_as_int();\n+\n+            // Logical file size must never exceed actual file size.\n+            // First two entries must be valid refs pointing inside the file\n+            if (logical_file_size > alloc.get_baseline() || table_names_ref == 0 ||\n+                table_names_ref > logical_file_size || (table_names_ref & 7) == 0 || tables_ref == 0 ||\n+                tables_ref > logical_file_size || (tables_ref & 7)) {\n+                std::string err = \"Invalid top array (ref, [0], [1], [2]): \" + util::to_string(top_ref) + \", \" +\n+                                  util::to_string(table_names_ref) + \", \" + util::to_string(tables_ref) + \", \" +\n+                                  util::to_string(logical_file_size);\n+                throw InvalidDatabase(err, \"\");\n+            }\n+            break;\n+        }\n+        default: {\n+            std::string err =\n+                \"Invalid top array size (ref, size): \" + util::to_string(top_ref) + \", \" + util::to_string(top_size);","path":"src/realm/group.cpp","position":34,"original_position":34,"commit_id":"352cdd9ff0cdd7a47f2b1c21712818b514946692","original_commit_id":"352cdd9ff0cdd7a47f2b1c21712818b514946692","user":{"login":"bmunkholm","id":1215687,"node_id":"MDQ6VXNlcjEyMTU2ODc=","avatar_url":"https://avatars2.githubusercontent.com/u/1215687?v=4","gravatar_id":"","url":"https://api.github.com/users/bmunkholm","html_url":"https://github.com/bmunkholm","followers_url":"https://api.github.com/users/bmunkholm/followers","following_url":"https://api.github.com/users/bmunkholm/following{/other_user}","gists_url":"https://api.github.com/users/bmunkholm/gists{/gist_id}","starred_url":"https://api.github.com/users/bmunkholm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmunkholm/subscriptions","organizations_url":"https://api.github.com/users/bmunkholm/orgs","repos_url":"https://api.github.com/users/bmunkholm/repos","events_url":"https://api.github.com/users/bmunkholm/events{/privacy}","received_events_url":"https://api.github.com/users/bmunkholm/received_events","type":"User","site_admin":false},"body":"```suggestion\r\n                \"Invalid top array size (ref=\" + util::to_string(top_ref) + \",  size=\" + util::to_string(top_size) + \"): \";\r\n```","created_at":"2018-12-21T14:58:15Z","updated_at":"2018-12-21T14:58:15Z","html_url":"https://github.com/realm/realm-core/pull/3203#discussion_r243602773","pull_request_url":"https://api.github.com/repos/realm/realm-core/pulls/3203","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/realm/realm-core/pulls/comments/243602773"},"html":{"href":"https://github.com/realm/realm-core/pull/3203#discussion_r243602773"},"pull_request":{"href":"https://api.github.com/repos/realm/realm-core/pulls/3203"}}},"pull_request":{"url":"https://api.github.com/repos/realm/realm-core/pulls/3203","id":240479289,"node_id":"MDExOlB1bGxSZXF1ZXN0MjQwNDc5Mjg5","html_url":"https://github.com/realm/realm-core/pull/3203","diff_url":"https://github.com/realm/realm-core/pull/3203.diff","patch_url":"https://github.com/realm/realm-core/pull/3203.patch","issue_url":"https://api.github.com/repos/realm/realm-core/issues/3203","number":3203,"state":"open","locked":false,"title":"Throw on invalid file","user":{"login":"jedelbo","id":572755,"node_id":"MDQ6VXNlcjU3Mjc1NQ==","avatar_url":"https://avatars2.githubusercontent.com/u/572755?v=4","gravatar_id":"","url":"https://api.github.com/users/jedelbo","html_url":"https://github.com/jedelbo","followers_url":"https://api.github.com/users/jedelbo/followers","following_url":"https://api.github.com/users/jedelbo/following{/other_user}","gists_url":"https://api.github.com/users/jedelbo/gists{/gist_id}","starred_url":"https://api.github.com/users/jedelbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jedelbo/subscriptions","organizations_url":"https://api.github.com/users/jedelbo/orgs","repos_url":"https://api.github.com/users/jedelbo/repos","events_url":"https://api.github.com/users/jedelbo/events{/privacy}","received_events_url":"https://api.github.com/users/jedelbo/received_events","type":"User","site_admin":false},"body":"This will leave it up to the user to decide what to do","created_at":"2018-12-21T13:51:10Z","updated_at":"2018-12-21T14:58:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"997abab977cf02385ef4f98032672ffef96f28c1","assignee":{"login":"jedelbo","id":572755,"node_id":"MDQ6VXNlcjU3Mjc1NQ==","avatar_url":"https://avatars2.githubusercontent.com/u/572755?v=4","gravatar_id":"","url":"https://api.github.com/users/jedelbo","html_url":"https://github.com/jedelbo","followers_url":"https://api.github.com/users/jedelbo/followers","following_url":"https://api.github.com/users/jedelbo/following{/other_user}","gists_url":"https://api.github.com/users/jedelbo/gists{/gist_id}","starred_url":"https://api.github.com/users/jedelbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jedelbo/subscriptions","organizations_url":"https://api.github.com/users/jedelbo/orgs","repos_url":"https://api.github.com/users/jedelbo/repos","events_url":"https://api.github.com/users/jedelbo/events{/privacy}","received_events_url":"https://api.github.com/users/jedelbo/received_events","type":"User","site_admin":false},"assignees":[{"login":"jedelbo","id":572755,"node_id":"MDQ6VXNlcjU3Mjc1NQ==","avatar_url":"https://avatars2.githubusercontent.com/u/572755?v=4","gravatar_id":"","url":"https://api.github.com/users/jedelbo","html_url":"https://github.com/jedelbo","followers_url":"https://api.github.com/users/jedelbo/followers","following_url":"https://api.github.com/users/jedelbo/following{/other_user}","gists_url":"https://api.github.com/users/jedelbo/gists{/gist_id}","starred_url":"https://api.github.com/users/jedelbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jedelbo/subscriptions","organizations_url":"https://api.github.com/users/jedelbo/orgs","repos_url":"https://api.github.com/users/jedelbo/repos","events_url":"https://api.github.com/users/jedelbo/events{/privacy}","received_events_url":"https://api.github.com/users/jedelbo/received_events","type":"User","site_admin":false}],"requested_reviewers":[{"login":"finnschiermer","id":5137726,"node_id":"MDQ6VXNlcjUxMzc3MjY=","avatar_url":"https://avatars2.githubusercontent.com/u/5137726?v=4","gravatar_id":"","url":"https://api.github.com/users/finnschiermer","html_url":"https://github.com/finnschiermer","followers_url":"https://api.github.com/users/finnschiermer/followers","following_url":"https://api.github.com/users/finnschiermer/following{/other_user}","gists_url":"https://api.github.com/users/finnschiermer/gists{/gist_id}","starred_url":"https://api.github.com/users/finnschiermer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/finnschiermer/subscriptions","organizations_url":"https://api.github.com/users/finnschiermer/orgs","repos_url":"https://api.github.com/users/finnschiermer/repos","events_url":"https://api.github.com/users/finnschiermer/events{/privacy}","received_events_url":"https://api.github.com/users/finnschiermer/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":320979145,"node_id":"MDU6TGFiZWwzMjA5NzkxNDU=","url":"https://api.github.com/repos/realm/realm-core/labels/T:Internal","name":"T:Internal","color":"c7def8","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/realm/realm-core/pulls/3203/commits","review_comments_url":"https://api.github.com/repos/realm/realm-core/pulls/3203/comments","review_comment_url":"https://api.github.com/repos/realm/realm-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/realm/realm-core/issues/3203/comments","statuses_url":"https://api.github.com/repos/realm/realm-core/statuses/352cdd9ff0cdd7a47f2b1c21712818b514946692","head":{"label":"realm:je/throw-on-invalid-file","ref":"je/throw-on-invalid-file","sha":"352cdd9ff0cdd7a47f2b1c21712818b514946692","user":{"login":"realm","id":7575099,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc1NzUwOTk=","avatar_url":"https://avatars0.githubusercontent.com/u/7575099?v=4","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":1917262,"node_id":"MDEwOlJlcG9zaXRvcnkxOTE3MjYy","name":"realm-core","full_name":"realm/realm-core","private":false,"owner":{"login":"realm","id":7575099,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc1NzUwOTk=","avatar_url":"https://avatars0.githubusercontent.com/u/7575099?v=4","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/realm/realm-core","description":"Core database component for the Realm Mobile Database SDKs","fork":false,"url":"https://api.github.com/repos/realm/realm-core","forks_url":"https://api.github.com/repos/realm/realm-core/forks","keys_url":"https://api.github.com/repos/realm/realm-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-core/teams","hooks_url":"https://api.github.com/repos/realm/realm-core/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-core/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-core/events","assignees_url":"https://api.github.com/repos/realm/realm-core/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-core/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-core/tags","blobs_url":"https://api.github.com/repos/realm/realm-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-core/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-core/languages","stargazers_url":"https://api.github.com/repos/realm/realm-core/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-core/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-core/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-core/subscription","commits_url":"https://api.github.com/repos/realm/realm-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-core/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-core/merges","archive_url":"https://api.github.com/repos/realm/realm-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-core/downloads","issues_url":"https://api.github.com/repos/realm/realm-core/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-core/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-core/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-core/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-core/releases{/id}","deployments_url":"https://api.github.com/repos/realm/realm-core/deployments","created_at":"2011-06-18T21:18:46Z","updated_at":"2018-12-21T13:10:52Z","pushed_at":"2018-12-21T13:51:10Z","git_url":"git://github.com/realm/realm-core.git","ssh_url":"git@github.com:realm/realm-core.git","clone_url":"https://github.com/realm/realm-core.git","svn_url":"https://github.com/realm/realm-core","homepage":"https://realm.io","size":54709,"stargazers_count":691,"watchers_count":691,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":60,"mirror_url":null,"archived":false,"open_issues_count":158,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":60,"open_issues":158,"watchers":691,"default_branch":"master"}},"base":{"label":"realm:master","ref":"master","sha":"804e90a069068d02cb06c1d011ef7326fb4cfdac","user":{"login":"realm","id":7575099,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc1NzUwOTk=","avatar_url":"https://avatars0.githubusercontent.com/u/7575099?v=4","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":1917262,"node_id":"MDEwOlJlcG9zaXRvcnkxOTE3MjYy","name":"realm-core","full_name":"realm/realm-core","private":false,"owner":{"login":"realm","id":7575099,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc1NzUwOTk=","avatar_url":"https://avatars0.githubusercontent.com/u/7575099?v=4","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/realm/realm-core","description":"Core database component for the Realm Mobile Database SDKs","fork":false,"url":"https://api.github.com/repos/realm/realm-core","forks_url":"https://api.github.com/repos/realm/realm-core/forks","keys_url":"https://api.github.com/repos/realm/realm-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-core/teams","hooks_url":"https://api.github.com/repos/realm/realm-core/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-core/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-core/events","assignees_url":"https://api.github.com/repos/realm/realm-core/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-core/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-core/tags","blobs_url":"https://api.github.com/repos/realm/realm-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-core/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-core/languages","stargazers_url":"https://api.github.com/repos/realm/realm-core/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-core/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-core/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-core/subscription","commits_url":"https://api.github.com/repos/realm/realm-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-core/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-core/merges","archive_url":"https://api.github.com/repos/realm/realm-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-core/downloads","issues_url":"https://api.github.com/repos/realm/realm-core/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-core/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-core/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-core/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-core/releases{/id}","deployments_url":"https://api.github.com/repos/realm/realm-core/deployments","created_at":"2011-06-18T21:18:46Z","updated_at":"2018-12-21T13:10:52Z","pushed_at":"2018-12-21T13:51:10Z","git_url":"git://github.com/realm/realm-core.git","ssh_url":"git@github.com:realm/realm-core.git","clone_url":"https://github.com/realm/realm-core.git","svn_url":"https://github.com/realm/realm-core","homepage":"https://realm.io","size":54709,"stargazers_count":691,"watchers_count":691,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":60,"mirror_url":null,"archived":false,"open_issues_count":158,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":60,"open_issues":158,"watchers":691,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/realm/realm-core/pulls/3203"},"html":{"href":"https://github.com/realm/realm-core/pull/3203"},"issue":{"href":"https://api.github.com/repos/realm/realm-core/issues/3203"},"comments":{"href":"https://api.github.com/repos/realm/realm-core/issues/3203/comments"},"review_comments":{"href":"https://api.github.com/repos/realm/realm-core/pulls/3203/comments"},"review_comment":{"href":"https://api.github.com/repos/realm/realm-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/realm/realm-core/pulls/3203/commits"},"statuses":{"href":"https://api.github.com/repos/realm/realm-core/statuses/352cdd9ff0cdd7a47f2b1c21712818b514946692"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"bmunkholm"}}