{"action":"created","issue":{"url":"https://api.github.com/repos/official-stockfish/Stockfish/issues/213","labels_url":"https://api.github.com/repos/official-stockfish/Stockfish/issues/213/labels{/name}","comments_url":"https://api.github.com/repos/official-stockfish/Stockfish/issues/213/comments","events_url":"https://api.github.com/repos/official-stockfish/Stockfish/issues/213/events","html_url":"https://github.com/official-stockfish/Stockfish/pull/213","id":54655098,"number":213,"title":"Fix a possible overflow in TT resize","user":{"login":"mcostalba","id":1099265,"avatar_url":"https://avatars.githubusercontent.com/u/1099265?v=3","gravatar_id":"","url":"https://api.github.com/users/mcostalba","html_url":"https://github.com/mcostalba","followers_url":"https://api.github.com/users/mcostalba/followers","following_url":"https://api.github.com/users/mcostalba/following{/other_user}","gists_url":"https://api.github.com/users/mcostalba/gists{/gist_id}","starred_url":"https://api.github.com/users/mcostalba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcostalba/subscriptions","organizations_url":"https://api.github.com/users/mcostalba/orgs","repos_url":"https://api.github.com/users/mcostalba/repos","events_url":"https://api.github.com/users/mcostalba/events{/privacy}","received_events_url":"https://api.github.com/users/mcostalba/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-01-17T08:09:31Z","updated_at":"2015-01-17T08:54:46Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/official-stockfish/Stockfish/pulls/213","html_url":"https://github.com/official-stockfish/Stockfish/pull/213","diff_url":"https://github.com/official-stockfish/Stockfish/pull/213.diff","patch_url":"https://github.com/official-stockfish/Stockfish/pull/213.patch"},"body":"On platforms where size_t is 32 bit, we\r\ncan have an overflow in this expression:\r\n\r\n(mbSize * 1024 * 1024)\r\n\r\nFix it explicitly defining mbSize as 64bit.\r\n\r\nAlso set correct max hash size for platforms\r\nwhere size_t is 32 bit.\r\n\r\nA small rename while there: now struct Cluster\r\nis definied inside class TranspositionTable so\r\nwe should drop the redundant TT prefix.\r\n\r\nNo functional change."},"comment":{"url":"https://api.github.com/repos/official-stockfish/Stockfish/issues/comments/70359820","html_url":"https://github.com/official-stockfish/Stockfish/pull/213#issuecomment-70359820","issue_url":"https://api.github.com/repos/official-stockfish/Stockfish/issues/213","id":70359820,"user":{"login":"mcostalba","id":1099265,"avatar_url":"https://avatars.githubusercontent.com/u/1099265?v=3","gravatar_id":"","url":"https://api.github.com/users/mcostalba","html_url":"https://github.com/mcostalba","followers_url":"https://api.github.com/users/mcostalba/followers","following_url":"https://api.github.com/users/mcostalba/following{/other_user}","gists_url":"https://api.github.com/users/mcostalba/gists{/gist_id}","starred_url":"https://api.github.com/users/mcostalba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcostalba/subscriptions","organizations_url":"https://api.github.com/users/mcostalba/orgs","repos_url":"https://api.github.com/users/mcostalba/repos","events_url":"https://api.github.com/users/mcostalba/events{/privacy}","received_events_url":"https://api.github.com/users/mcostalba/received_events","type":"User","site_admin":false},"created_at":"2015-01-17T08:54:46Z","updated_at":"2015-01-17T08:54:46Z","body":"In 32 bit max hash size is 64GB (65536 MB) as you can see in ucioption.cpp\n\nnow if mbSize is 65535 you have an overflow in (mbSize * 1024 * 1024) but\nyou are well within with\n\nsize_t newClusterCount = size_t(1) << msb((mbSize * 1024 * 1024) /\nsizeof(TTCluster));\n\nmem = calloc(clusterCount * sizeof(TTCluster) + CacheLineSize - 1, 1);\n\n\nI am not sure your solution is simpler, once you have done the math and\nverified (I did it just now):\n\n  mbSize = 65535;\n\n  size_t newClusterCount2 = size_t(1) << msb((mbSize * 1024 * 1024) /\nsizeof(TTCluster));\n\n  std::cerr << msb((mbSize * 1024 * 1024) / sizeof(TTCluster)) << std::endl;\n  std::cerr << newClusterCount2 << std::endl;\n\nI got:\n\n30\n1073741824"}}