{"action":"opened","number":7175,"pull_request":{"url":"https://api.github.com/repos/numpy/numpy/pulls/7175","id":58073179,"html_url":"https://github.com/numpy/numpy/pull/7175","diff_url":"https://github.com/numpy/numpy/pull/7175.diff","patch_url":"https://github.com/numpy/numpy/pull/7175.patch","issue_url":"https://api.github.com/repos/numpy/numpy/issues/7175","number":7175,"state":"open","locked":false,"title":"BUG: Invalid read of size 4 in PyArray_FromFile","user":{"login":"rainwoodman","id":138060,"avatar_url":"https://avatars.githubusercontent.com/u/138060?v=3","gravatar_id":"","url":"https://api.github.com/users/rainwoodman","html_url":"https://github.com/rainwoodman","followers_url":"https://api.github.com/users/rainwoodman/followers","following_url":"https://api.github.com/users/rainwoodman/following{/other_user}","gists_url":"https://api.github.com/users/rainwoodman/gists{/gist_id}","starred_url":"https://api.github.com/users/rainwoodman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rainwoodman/subscriptions","organizations_url":"https://api.github.com/users/rainwoodman/orgs","repos_url":"https://api.github.com/users/rainwoodman/repos","events_url":"https://api.github.com/users/rainwoodman/events{/privacy}","received_events_url":"https://api.github.com/users/rainwoodman/received_events","type":"User","site_admin":false},"body":"When the input dtype has a subarray, the dtype is DECREFed by PyArray_NewFromDescr, \r\nbefore dtype->elsize is accessed. \r\n\r\nIf no one else holds a reference to the dtype object, then the dtype object will be destroyed, \r\nand dtype->elsize shall not be accessed. \r\nThis raises an error in Valgrind, and occasionally crashes innocently looking code.\r\ne.g. ```numpy.fromfile('filename', dtype=('f8', 3'))``` \r\n\r\nA workaround would be\r\n```dtype=numpy.dtype(('f8', 3)); numpy.fromfile('filename', dtype=dtype)```\r\n\r\nThis affects versions as early as 1.9.2 (where I found this bug) and seems to be still relevant today. \r\nI hope someone can prove me wrong.\r\nThis PR is just a demonstration of the idea. I didn't try to compile it.\r\n\r\nValgrind log:\r\n```\r\n==17479== Invalid read of size 4\r\n==17479==    at 0x1CD0BB88: UnknownInlinedFun (stdio2.h:295)\r\n==17479==    by 0x1CD0BB88: array_fromfile_binary (ctors.c:3177)\r\n==17479==    by 0x1CD0BB88: PyArray_FromFile (ctors.c:3304)\r\n==17479==    by 0x1CD886B5: array_fromfile (multiarraymodule.c:2040)\r\n==17479==    by 0x37AB6E2571: do_call (ceval.c:4327)\r\n==17479==    by 0x37AB6E2571: call_function (ceval.c:4135)\r\n==17479==    by 0x37AB6E2571: PyEval_EvalFrameEx (ceval.c:2755)\r\n==17479==    by 0x37AB6E2665: fast_function (ceval.c:4198)\r\n==17479==    by 0x37AB6E2665: call_function (ceval.c:4133)\r\n==17479==    by 0x37AB6E2665: PyEval_EvalFrameEx (ceval.c:2755)\r\n==17479==    by 0x37AB6E2665: fast_function (ceval.c:4198)\r\n==17479==    by 0x37AB6E2665: call_function (ceval.c:4133)\r\n==17479==    by 0x37AB6E2665: PyEval_EvalFrameEx (ceval.c:2755)\r\n==17479==    by 0x37AB664DCB: gen_send_ex.isra.0 (genobject.c:85)\r\n==17479==    by 0x37AB6DE419: PyEval_EvalFrameEx (ceval.c:2586)\r\n==17479==    by 0x37AB664DCB: gen_send_ex.isra.0 (genobject.c:85)\r\n==17479==    by 0x37AB6DE419: PyEval_EvalFrameEx (ceval.c:2586)\r\n==17479==    by 0x37AB6E2665: fast_function (ceval.c:4198)\r\n==17479==    by 0x37AB6E2665: call_function (ceval.c:4133)\r\n==17479==    by 0x37AB6E2665: PyEval_EvalFrameEx (ceval.c:2755)\r\n==17479==    by 0x37AB6E36B3: PyEval_EvalCodeEx (ceval.c:3344)\r\n==17479==    by 0x37AB6E25C5: fast_function (ceval.c:4208)\r\n==17479==    by 0x37AB6E25C5: call_function (ceval.c:4133)\r\n==17479==    by 0x37AB6E25C5: PyEval_EvalFrameEx (ceval.c:2755)\r\n==17479==  Address 0x113bef20 is 32 bytes inside a block of size 88 free'd\r\n==17479==    at 0x4A07D6A: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)\r\n==17479==    by 0x1CD07C15: _update_descr_and_dimensions (ctors.c:273)\r\n==17479==    by 0x1CD07C15: PyArray_NewFromDescr_int (ctors.c:900)\r\n==17479==    by 0x1CD0BB76: PyArray_NewFromDescr (ctors.c:1121)\r\n==17479==    by 0x1CD0BB76: array_fromfile_binary (ctors.c:3168)\r\n==17479==    by 0x1CD0BB76: PyArray_FromFile (ctors.c:3304)\r\n==17479==    by 0x1CD886B5: array_fromfile (multiarraymodule.c:2040)\r\n==17479==    by 0x37AB6E2571: do_call (ceval.c:4327)\r\n==17479==    by 0x37AB6E2571: call_function (ceval.c:4135)\r\n==17479==    by 0x37AB6E2571: PyEval_EvalFrameEx (ceval.c:2755)\r\n==17479==    by 0x37AB6E2665: fast_function (ceval.c:4198)\r\n==17479==    by 0x37AB6E2665: call_function (ceval.c:4133)\r\n==17479==    by 0x37AB6E2665: PyEval_EvalFrameEx (ceval.c:2755)\r\n==17479==    by 0x37AB6E2665: fast_function (ceval.c:4198)\r\n==17479==    by 0x37AB6E2665: call_function (ceval.c:4133)\r\n==17479==    by 0x37AB6E2665: PyEval_EvalFrameEx (ceval.c:2755)\r\n==17479==    by 0x37AB664DCB: gen_send_ex.isra.0 (genobject.c:85)\r\n==17479==    by 0x37AB6DE419: PyEval_EvalFrameEx (ceval.c:2586)\r\n==17479==    by 0x37AB664DCB: gen_send_ex.isra.0 (genobject.c:85)\r\n==17479==    by 0x37AB6DE419: PyEval_EvalFrameEx (ceval.c:2586)\r\n==17479==    by 0x37AB6E2665: fast_function (ceval.c:4198)\r\n==17479==    by 0x37AB6E2665: call_function (ceval.c:4133)\r\n==17479==    by 0x37AB6E2665: PyEval_EvalFrameEx (ceval.c:2755)\r\n```","created_at":"2016-02-03T00:23:59Z","updated_at":"2016-02-03T00:23:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6b019eed16cb5503ce9c712ff2eb33e21a8f69cd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/numpy/numpy/pulls/7175/commits","review_comments_url":"https://api.github.com/repos/numpy/numpy/pulls/7175/comments","review_comment_url":"https://api.github.com/repos/numpy/numpy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/numpy/numpy/issues/7175/comments","statuses_url":"https://api.github.com/repos/numpy/numpy/statuses/c4a990563b2c85747eb9cdccc5a783846d0071a0","head":{"label":"rainwoodman:patch-1","ref":"patch-1","sha":"c4a990563b2c85747eb9cdccc5a783846d0071a0","user":{"login":"rainwoodman","id":138060,"avatar_url":"https://avatars.githubusercontent.com/u/138060?v=3","gravatar_id":"","url":"https://api.github.com/users/rainwoodman","html_url":"https://github.com/rainwoodman","followers_url":"https://api.github.com/users/rainwoodman/followers","following_url":"https://api.github.com/users/rainwoodman/following{/other_user}","gists_url":"https://api.github.com/users/rainwoodman/gists{/gist_id}","starred_url":"https://api.github.com/users/rainwoodman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rainwoodman/subscriptions","organizations_url":"https://api.github.com/users/rainwoodman/orgs","repos_url":"https://api.github.com/users/rainwoodman/repos","events_url":"https://api.github.com/users/rainwoodman/events{/privacy}","received_events_url":"https://api.github.com/users/rainwoodman/received_events","type":"User","site_admin":false},"repo":{"id":41000179,"name":"numpy","full_name":"rainwoodman/numpy","owner":{"login":"rainwoodman","id":138060,"avatar_url":"https://avatars.githubusercontent.com/u/138060?v=3","gravatar_id":"","url":"https://api.github.com/users/rainwoodman","html_url":"https://github.com/rainwoodman","followers_url":"https://api.github.com/users/rainwoodman/followers","following_url":"https://api.github.com/users/rainwoodman/following{/other_user}","gists_url":"https://api.github.com/users/rainwoodman/gists{/gist_id}","starred_url":"https://api.github.com/users/rainwoodman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rainwoodman/subscriptions","organizations_url":"https://api.github.com/users/rainwoodman/orgs","repos_url":"https://api.github.com/users/rainwoodman/repos","events_url":"https://api.github.com/users/rainwoodman/events{/privacy}","received_events_url":"https://api.github.com/users/rainwoodman/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rainwoodman/numpy","description":"Numpy main repository","fork":true,"url":"https://api.github.com/repos/rainwoodman/numpy","forks_url":"https://api.github.com/repos/rainwoodman/numpy/forks","keys_url":"https://api.github.com/repos/rainwoodman/numpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rainwoodman/numpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rainwoodman/numpy/teams","hooks_url":"https://api.github.com/repos/rainwoodman/numpy/hooks","issue_events_url":"https://api.github.com/repos/rainwoodman/numpy/issues/events{/number}","events_url":"https://api.github.com/repos/rainwoodman/numpy/events","assignees_url":"https://api.github.com/repos/rainwoodman/numpy/assignees{/user}","branches_url":"https://api.github.com/repos/rainwoodman/numpy/branches{/branch}","tags_url":"https://api.github.com/repos/rainwoodman/numpy/tags","blobs_url":"https://api.github.com/repos/rainwoodman/numpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rainwoodman/numpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rainwoodman/numpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/rainwoodman/numpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rainwoodman/numpy/statuses/{sha}","languages_url":"https://api.github.com/repos/rainwoodman/numpy/languages","stargazers_url":"https://api.github.com/repos/rainwoodman/numpy/stargazers","contributors_url":"https://api.github.com/repos/rainwoodman/numpy/contributors","subscribers_url":"https://api.github.com/repos/rainwoodman/numpy/subscribers","subscription_url":"https://api.github.com/repos/rainwoodman/numpy/subscription","commits_url":"https://api.github.com/repos/rainwoodman/numpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/rainwoodman/numpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/rainwoodman/numpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/rainwoodman/numpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/rainwoodman/numpy/contents/{+path}","compare_url":"https://api.github.com/repos/rainwoodman/numpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rainwoodman/numpy/merges","archive_url":"https://api.github.com/repos/rainwoodman/numpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rainwoodman/numpy/downloads","issues_url":"https://api.github.com/repos/rainwoodman/numpy/issues{/number}","pulls_url":"https://api.github.com/repos/rainwoodman/numpy/pulls{/number}","milestones_url":"https://api.github.com/repos/rainwoodman/numpy/milestones{/number}","notifications_url":"https://api.github.com/repos/rainwoodman/numpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rainwoodman/numpy/labels{/name}","releases_url":"https://api.github.com/repos/rainwoodman/numpy/releases{/id}","deployments_url":"https://api.github.com/repos/rainwoodman/numpy/deployments","created_at":"2015-08-18T22:15:28Z","updated_at":"2015-08-18T22:15:33Z","pushed_at":"2016-02-03T00:22:43Z","git_url":"git://github.com/rainwoodman/numpy.git","ssh_url":"git@github.com:rainwoodman/numpy.git","clone_url":"https://github.com/rainwoodman/numpy.git","svn_url":"https://github.com/rainwoodman/numpy","homepage":"http://www.numpy.org/","size":43474,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"numpy:master","ref":"master","sha":"12ec338c23f3db1e155661fdbf098a546e48dc1e","user":{"login":"numpy","id":288276,"avatar_url":"https://avatars.githubusercontent.com/u/288276?v=3","gravatar_id":"","url":"https://api.github.com/users/numpy","html_url":"https://github.com/numpy","followers_url":"https://api.github.com/users/numpy/followers","following_url":"https://api.github.com/users/numpy/following{/other_user}","gists_url":"https://api.github.com/users/numpy/gists{/gist_id}","starred_url":"https://api.github.com/users/numpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numpy/subscriptions","organizations_url":"https://api.github.com/users/numpy/orgs","repos_url":"https://api.github.com/users/numpy/repos","events_url":"https://api.github.com/users/numpy/events{/privacy}","received_events_url":"https://api.github.com/users/numpy/received_events","type":"Organization","site_admin":false},"repo":{"id":908607,"name":"numpy","full_name":"numpy/numpy","owner":{"login":"numpy","id":288276,"avatar_url":"https://avatars.githubusercontent.com/u/288276?v=3","gravatar_id":"","url":"https://api.github.com/users/numpy","html_url":"https://github.com/numpy","followers_url":"https://api.github.com/users/numpy/followers","following_url":"https://api.github.com/users/numpy/following{/other_user}","gists_url":"https://api.github.com/users/numpy/gists{/gist_id}","starred_url":"https://api.github.com/users/numpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numpy/subscriptions","organizations_url":"https://api.github.com/users/numpy/orgs","repos_url":"https://api.github.com/users/numpy/repos","events_url":"https://api.github.com/users/numpy/events{/privacy}","received_events_url":"https://api.github.com/users/numpy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/numpy/numpy","description":"Numpy main repository","fork":false,"url":"https://api.github.com/repos/numpy/numpy","forks_url":"https://api.github.com/repos/numpy/numpy/forks","keys_url":"https://api.github.com/repos/numpy/numpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/numpy/numpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/numpy/numpy/teams","hooks_url":"https://api.github.com/repos/numpy/numpy/hooks","issue_events_url":"https://api.github.com/repos/numpy/numpy/issues/events{/number}","events_url":"https://api.github.com/repos/numpy/numpy/events","assignees_url":"https://api.github.com/repos/numpy/numpy/assignees{/user}","branches_url":"https://api.github.com/repos/numpy/numpy/branches{/branch}","tags_url":"https://api.github.com/repos/numpy/numpy/tags","blobs_url":"https://api.github.com/repos/numpy/numpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/numpy/numpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/numpy/numpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/numpy/numpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/numpy/numpy/statuses/{sha}","languages_url":"https://api.github.com/repos/numpy/numpy/languages","stargazers_url":"https://api.github.com/repos/numpy/numpy/stargazers","contributors_url":"https://api.github.com/repos/numpy/numpy/contributors","subscribers_url":"https://api.github.com/repos/numpy/numpy/subscribers","subscription_url":"https://api.github.com/repos/numpy/numpy/subscription","commits_url":"https://api.github.com/repos/numpy/numpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/numpy/numpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/numpy/numpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/numpy/numpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/numpy/numpy/contents/{+path}","compare_url":"https://api.github.com/repos/numpy/numpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/numpy/numpy/merges","archive_url":"https://api.github.com/repos/numpy/numpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/numpy/numpy/downloads","issues_url":"https://api.github.com/repos/numpy/numpy/issues{/number}","pulls_url":"https://api.github.com/repos/numpy/numpy/pulls{/number}","milestones_url":"https://api.github.com/repos/numpy/numpy/milestones{/number}","notifications_url":"https://api.github.com/repos/numpy/numpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/numpy/numpy/labels{/name}","releases_url":"https://api.github.com/repos/numpy/numpy/releases{/id}","deployments_url":"https://api.github.com/repos/numpy/numpy/deployments","created_at":"2010-09-13T23:02:39Z","updated_at":"2016-02-02T09:04:49Z","pushed_at":"2016-02-03T00:24:00Z","git_url":"git://github.com/numpy/numpy.git","ssh_url":"git@github.com:numpy/numpy.git","clone_url":"https://github.com/numpy/numpy.git","svn_url":"https://github.com/numpy/numpy","homepage":"http://www.numpy.org/","size":64718,"stargazers_count":2581,"watchers_count":2581,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1354,"mirror_url":null,"open_issues_count":1104,"forks":1354,"open_issues":1104,"watchers":2581,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/numpy/numpy/pulls/7175"},"html":{"href":"https://github.com/numpy/numpy/pull/7175"},"issue":{"href":"https://api.github.com/repos/numpy/numpy/issues/7175"},"comments":{"href":"https://api.github.com/repos/numpy/numpy/issues/7175/comments"},"review_comments":{"href":"https://api.github.com/repos/numpy/numpy/pulls/7175/comments"},"review_comment":{"href":"https://api.github.com/repos/numpy/numpy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/numpy/numpy/pulls/7175/commits"},"statuses":{"href":"https://api.github.com/repos/numpy/numpy/statuses/c4a990563b2c85747eb9cdccc5a783846d0071a0"}},"merged":false,"mergeable":true,"mergeable_state":"clean","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":8,"deletions":1,"changed_files":1}}