{"action":"created","issue":{"url":"https://api.github.com/repos/briansmith/ring/issues/41","labels_url":"https://api.github.com/repos/briansmith/ring/issues/41/labels{/name}","comments_url":"https://api.github.com/repos/briansmith/ring/issues/41/comments","events_url":"https://api.github.com/repos/briansmith/ring/issues/41/events","html_url":"https://github.com/briansmith/ring/issues/41","id":113098573,"number":41,"title":"Crashing bug using reference to digest::SHA1","user":{"login":"badboy","id":2129,"avatar_url":"https://avatars.githubusercontent.com/u/2129?v=3","gravatar_id":"","url":"https://api.github.com/users/badboy","html_url":"https://github.com/badboy","followers_url":"https://api.github.com/users/badboy/followers","following_url":"https://api.github.com/users/badboy/following{/other_user}","gists_url":"https://api.github.com/users/badboy/gists{/gist_id}","starred_url":"https://api.github.com/users/badboy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/badboy/subscriptions","organizations_url":"https://api.github.com/users/badboy/orgs","repos_url":"https://api.github.com/users/badboy/repos","events_url":"https://api.github.com/users/badboy/events{/privacy}","received_events_url":"https://api.github.com/users/badboy/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/briansmith/ring/labels/usability","name":"usability","color":"bfd4f2"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-10-23T20:54:19Z","updated_at":"2015-11-09T07:20:46Z","closed_at":"2015-11-09T07:20:46Z","body":"When using your proposed code directly (badboy/nobsign/issues/2) I hit a bug crashing (and coredumping) the compiler.\r\n\r\nThis little piece of Rust reproduces it:\r\n\r\n```rust\r\nextern crate ring;\r\n\r\nstatic _ALGORITHM: &'static ring::digest::Algorithm = &ring::digest::SHA1;\r\n\r\npub fn bug() {\r\n    vec![0u8; ring::digest::SHA1.digest_len];\r\n}\r\n```\r\n\r\nCompiling that (add this repo as a dependency to a crate, then `cargo build`) leads to:\r\n\r\n```\r\nrustc: /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/llvm/lib/IR/Constants.cpp:2044: static llvm::Constant* llvm::ConstantExpr::getGetElementPtr(llvm::Type*, llvm::Constant*, llvm::ArrayRef<llvm::Value*>, bool, llvm::Type*): Assertion `DestTy && \"GEP indices invalid!\"' failed.\r\n```\r\n\r\nand a coredump.\r\n\r\n@kimundi was so nice to explain a bit:\r\n\r\n> library does wrong unsafe things => invariants are violated => rust compiler emits IR with UB to llvm => llvm in debug mode checks somke of the invariants and triggers an assertion error => assertion do abort the process => abort is implemented as a invalid instruction => core dump\r\n\r\nIt seems that this usage of references to `digest::SHA1` (which [itself is a static](https://github.com/briansmith/ring/blob/master/src/digest.rs#L207)) leads to this undefined behavior.\r\n\r\nOf course it might be nice if rustc can prevent this.\r\nBut nevertheless ring should try to provide safe abstractions."},"comment":{"url":"https://api.github.com/repos/briansmith/ring/issues/comments/154977564","html_url":"https://github.com/briansmith/ring/issues/41#issuecomment-154977564","issue_url":"https://api.github.com/repos/briansmith/ring/issues/41","id":154977564,"user":{"login":"briansmith","id":16816,"avatar_url":"https://avatars.githubusercontent.com/u/16816?v=3","gravatar_id":"","url":"https://api.github.com/users/briansmith","html_url":"https://github.com/briansmith","followers_url":"https://api.github.com/users/briansmith/followers","following_url":"https://api.github.com/users/briansmith/following{/other_user}","gists_url":"https://api.github.com/users/briansmith/gists{/gist_id}","starred_url":"https://api.github.com/users/briansmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/briansmith/subscriptions","organizations_url":"https://api.github.com/users/briansmith/orgs","repos_url":"https://api.github.com/users/briansmith/repos","events_url":"https://api.github.com/users/briansmith/events{/privacy}","received_events_url":"https://api.github.com/users/briansmith/received_events","type":"User","site_admin":false},"created_at":"2015-11-09T07:20:46Z","updated_at":"2015-11-09T07:20:46Z","body":"I'm going to close this since it is a rustc issue, not a *ring* issue. Thanks for reporting it though!"}}