{"action":"created","issue":{"url":"https://api.github.com/repos/woboq/woboq_codebrowser/issues/38","repository_url":"https://api.github.com/repos/woboq/woboq_codebrowser","labels_url":"https://api.github.com/repos/woboq/woboq_codebrowser/issues/38/labels{/name}","comments_url":"https://api.github.com/repos/woboq/woboq_codebrowser/issues/38/comments","events_url":"https://api.github.com/repos/woboq/woboq_codebrowser/issues/38/events","html_url":"https://github.com/woboq/woboq_codebrowser/issues/38","id":148977458,"number":38,"title":"Crash in handleUrlsInComment","user":{"login":"ClockMan","id":1038566,"avatar_url":"https://avatars.githubusercontent.com/u/1038566?v=3","gravatar_id":"","url":"https://api.github.com/users/ClockMan","html_url":"https://github.com/ClockMan","followers_url":"https://api.github.com/users/ClockMan/followers","following_url":"https://api.github.com/users/ClockMan/following{/other_user}","gists_url":"https://api.github.com/users/ClockMan/gists{/gist_id}","starred_url":"https://api.github.com/users/ClockMan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ClockMan/subscriptions","organizations_url":"https://api.github.com/users/ClockMan/orgs","repos_url":"https://api.github.com/users/ClockMan/repos","events_url":"https://api.github.com/users/ClockMan/events{/privacy}","received_events_url":"https://api.github.com/users/ClockMan/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-17T18:02:17Z","updated_at":"2016-04-17T19:24:33Z","closed_at":"2016-04-17T18:31:13Z","body":"There is access to -1 index of string somwhere.\r\nHad problem to track it down, but as workaround I added index checking:\r\n\r\n```\r\n280 static void handleUrlsInComment(Generator& generator, llvm::StringRef rawString, int commentStart)\r\n281 {\r\n282     std::size_t pos = 0;\r\n283     while ((pos = rawString.find(\"http\", pos)) != llvm::StringRef::npos) {\r\n284         int begin = pos;\r\n285         pos +=4;\r\n286         if (begin != 0 && llvm::StringRef(\" \\t/*[]()<>|:\\\"'{}\").find(rawString[begin-1]) == llvm::StringRef::npos) {\r\n287             // the URL need to be the first character, or follow a space or one of the character\r\n288             continue;\r\n289         }\r\n290         if (rawString[pos] == 's') pos++;\r\n291         if (!rawString.substr(pos).startswith(\"://\"))\r\n292             continue;\r\n293         pos+=3;\r\n294         // We have an URL\r\n295\r\n296         llvm::StringRef urlChars = \"-._~:/?#[]@!$&'()*+,;=%\"; // chars valid in the URL\r\n297         while(pos>=0 && (pos+1) < rawString.size() && (std::isalnum(rawString[pos]) ||\r\n298                 urlChars.find(rawString[pos]) != llvm::StringRef::npos))\r\n299             pos++;\r\n300\r\n301         // don't end with a period\r\n302         if (pos>0 && rawString[pos-1]=='.') pos--;\r\n303\r\n304         // Don't end with a closing parenthese or bracket unless the URL contains an opening one\r\n305         // (e.g. wikipedia urls)\r\n306         auto candidate = rawString.substr(begin, pos-begin);\r\n307         if (pos > 0 && rawString[pos-1]==')' && candidate.find('(') == llvm::StringRef::npos) pos--;\r\n308         if (pos > 0 && rawString[pos-1]==']' && candidate.find('[') == llvm::StringRef::npos) pos--;\r\n309\r\n310         // don't end with a period\r\n311         if (pos > 0 && rawString[pos-1]=='.') pos--;\r\n312\r\n313         auto len = pos - begin;\r\n314         generator.addTag(\"a\", \"href=\\\"\" % rawString.substr(begin, len) % \"\\\"\",\r\n315                          commentStart+begin, len);\r\n316     }\r\n317\r\n318 }\r\n```"},"comment":{"url":"https://api.github.com/repos/woboq/woboq_codebrowser/issues/comments/211090926","html_url":"https://github.com/woboq/woboq_codebrowser/issues/38#issuecomment-211090926","issue_url":"https://api.github.com/repos/woboq/woboq_codebrowser/issues/38","id":211090926,"user":{"login":"ClockMan","id":1038566,"avatar_url":"https://avatars.githubusercontent.com/u/1038566?v=3","gravatar_id":"","url":"https://api.github.com/users/ClockMan","html_url":"https://github.com/ClockMan","followers_url":"https://api.github.com/users/ClockMan/followers","following_url":"https://api.github.com/users/ClockMan/following{/other_user}","gists_url":"https://api.github.com/users/ClockMan/gists{/gist_id}","starred_url":"https://api.github.com/users/ClockMan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ClockMan/subscriptions","organizations_url":"https://api.github.com/users/ClockMan/orgs","repos_url":"https://api.github.com/users/ClockMan/repos","events_url":"https://api.github.com/users/ClockMan/events{/privacy}","received_events_url":"https://api.github.com/users/ClockMan/received_events","type":"User","site_admin":false},"created_at":"2016-04-17T19:24:33Z","updated_at":"2016-04-17T19:24:33Z","body":"Thanks"}}