{"action":"created","comment":{"url":"https://api.github.com/repos/netty/netty/pulls/comments/68423606","id":68423606,"diff_hunk":"@@ -0,0 +1,131 @@\n+/*\n+ * Copyright 2016 The Netty Project\n+ *\n+ * The Netty Project licenses this file to you under the Apache License,\n+ * version 2.0 (the \"License\"); you may not use this file except in compliance\n+ * with the License. You may obtain a copy of the License at:\n+ *\n+ *   http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n+ * License for the specific language governing permissions and limitations\n+ * under the License.\n+ */\n+package io.netty.util.internal;\n+\n+public final class ConstantTimeUtils {\n+    private ConstantTimeUtils() { }\n+\n+    /**\n+     * Compare two {@code int}s without leaking timing information.\n+     * <p>\n+     * The {@code int} return type is intentional and is designed to allow cascading of constant time operations:\n+     * <pre>\n+     *     int v1 = 1;\n+     *     int v1 = 1;\n+     *     int v1 = 1;\n+     *     int v1 = 500;\n+     *     boolean equals = (equalsConstantTime(l1, l2) & equalsConstantTime(l3, l4)) != 0;\n+     * </pre>\n+     * @param x the first value.\n+     * @param y the second value.\n+     * @return {@code 0} if not equal. {@code 1} if equal.\n+     */\n+    public static int equalsConstantTime(int x, int y) {\n+        int z = -1 ^ (x ^ y);\n+        z &= z >> 16;\n+        z &= z >> 8;\n+        z &= z >> 4;\n+        z &= z >> 2;\n+        z &= z >> 1;\n+        return z & 1;\n+    }\n+\n+    /**\n+     * Compare two {@code longs}s without leaking timing information.\n+     * <p>\n+     * The {@code int} return type is intentional and is designed to allow cascading of constant time operations:\n+     * <pre>\n+     *     long v1 = 1;\n+     *     long v1 = 1;\n+     *     long v1 = 1;\n+     *     long v1 = 500;\n+     *     boolean equals = (equalsConstantTime(l1, l2) & equalsConstantTime(l3, l4)) != 0;\n+     * </pre>\n+     * @param x the first value.\n+     * @param y the second value.\n+     * @return {@code 0} if not equal. {@code 1} if equal.\n+     */\n+    public static int equalsConstantTime(long x, long y) {\n+        long z = -1L ^ (x ^ y);\n+        z &= z >> 32;\n+        z &= z >> 16;\n+        z &= z >> 8;\n+        z &= z >> 4;\n+        z &= z >> 2;\n+        z &= z >> 1;\n+        return (int) (z & 1);\n+    }\n+\n+    /**\n+     * Compare two {@code byte} arrays for equality without leaking timing information.\n+     * For performance reasons no bounds checking on the parameters is performed.\n+     * <p>\n+     * The {@code int} return type is intentional and is designed to allow cascading of constant time operations:\n+     * <pre>\n+     *     byte[] s1 = new {1, 2, 3};\n+     *     byte[] s2 = new {1, 2, 3};\n+     *     byte[] s3 = new {1, 2, 3};\n+     *     byte[] s4 = new {4, 5, 6};\n+     *     boolean equals = (equalsConstantTime(s1, 0, s2, 0, s1.length) &\n+     *                       equalsConstantTime(s3, 0, s4, 0, s3.length)) != 0;\n+     * </pre>\n+     * @param bytes1 the first byte array.\n+     * @param startPos1 the position (inclusive) to start comparing in {@code bytes1}.\n+     * @param bytes2 the second byte array.\n+     * @param startPos2 the position (inclusive) to start comparing in {@code bytes2}.\n+     * @param length the amount of bytes to compare. This is assumed to be validated as not going out of bounds\n+     * by the caller.\n+     * @return {@code 0} if not equal. {@code 1} if equal.\n+     */\n+    public static int equalsConstantTime(byte[] bytes1, int startPos1,","path":"common/src/main/java/io/netty/util/internal/ConstantTimeUtils.java","position":93,"original_position":93,"commit_id":"b90e35f69caffa1b7322742b60621b41fc02650a","original_commit_id":"b90e35f69caffa1b7322742b60621b41fc02650a","user":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"body":"> I think you may still need to do a bounds check. Something like bytes1.length - startPos1 == bytes2.length - start2Pos.\r\n\r\nThe bounds check is done through the length check. The \"no bounds checking behavior\" is also specified in the [javadocs](https://github.com/netty/netty/pull/5446/files#diff-ea8860513cb8af4c4392d1e295326fc6R639), PlatformDependent/ConstantTimeUtils are part of the internal API, and this behavior is consistent with [PlatformDependent.equals](https://github.com/netty/netty/blame/4.1/common/src/main/java/io/netty/util/internal/PlatformDependent.java#L625).","created_at":"2016-06-24T16:25:31Z","updated_at":"2016-06-24T16:25:31Z","html_url":"https://github.com/netty/netty/pull/5446#discussion_r68423606","pull_request_url":"https://api.github.com/repos/netty/netty/pulls/5446","_links":{"self":{"href":"https://api.github.com/repos/netty/netty/pulls/comments/68423606"},"html":{"href":"https://github.com/netty/netty/pull/5446#discussion_r68423606"},"pull_request":{"href":"https://api.github.com/repos/netty/netty/pulls/5446"}}},"pull_request":{"url":"https://api.github.com/repos/netty/netty/pulls/5446","id":74874348,"html_url":"https://github.com/netty/netty/pull/5446","diff_url":"https://github.com/netty/netty/pull/5446.diff","patch_url":"https://github.com/netty/netty/pull/5446.patch","issue_url":"https://api.github.com/repos/netty/netty/issues/5446","number":5446,"state":"open","locked":false,"title":"HpackUtil.equals performance improvement","user":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"body":"Motivation:\r\nPR #5355 modified interfaces to reduce GC related to the HPACK code. However this came with an anticipated performance regression related to HpackUtil.equals due to AsciiString's increase cost of charAt(..). We should mitigate this performance regression.\r\n\r\nModifications:\r\n- Introduce an equals method in PlatformDependent which doesn't leak timing information and use this in HpcakUtil.equals\r\n\r\nResult:\r\nFixes https://github.com/netty/netty/issues/5436","created_at":"2016-06-22T23:25:49Z","updated_at":"2016-06-24T16:25:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"63a137a665cd2b3381f91d0a13dde5c8bb72348f","assignee":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"assignees":[{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/netty/netty/milestones/143","html_url":"https://github.com/netty/netty/milestones/4.1.2.Final","labels_url":"https://api.github.com/repos/netty/netty/milestones/143/labels","id":1814078,"number":143,"title":"4.1.2.Final","description":"","creator":{"login":"normanmaurer","id":439362,"avatar_url":"https://avatars.githubusercontent.com/u/439362?v=3","gravatar_id":"","url":"https://api.github.com/users/normanmaurer","html_url":"https://github.com/normanmaurer","followers_url":"https://api.github.com/users/normanmaurer/followers","following_url":"https://api.github.com/users/normanmaurer/following{/other_user}","gists_url":"https://api.github.com/users/normanmaurer/gists{/gist_id}","starred_url":"https://api.github.com/users/normanmaurer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/normanmaurer/subscriptions","organizations_url":"https://api.github.com/users/normanmaurer/orgs","repos_url":"https://api.github.com/users/normanmaurer/repos","events_url":"https://api.github.com/users/normanmaurer/events{/privacy}","received_events_url":"https://api.github.com/users/normanmaurer/received_events","type":"User","site_admin":false},"open_issues":48,"closed_issues":14,"state":"open","created_at":"2016-06-07T18:30:16Z","updated_at":"2016-06-23T23:16:06Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/netty/netty/pulls/5446/commits","review_comments_url":"https://api.github.com/repos/netty/netty/pulls/5446/comments","review_comment_url":"https://api.github.com/repos/netty/netty/pulls/comments{/number}","comments_url":"https://api.github.com/repos/netty/netty/issues/5446/comments","statuses_url":"https://api.github.com/repos/netty/netty/statuses/b90e35f69caffa1b7322742b60621b41fc02650a","head":{"label":"Scottmitch:hpack_equals_improve","ref":"hpack_equals_improve","sha":"b90e35f69caffa1b7322742b60621b41fc02650a","user":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"repo":{"id":21251366,"name":"netty","full_name":"Scottmitch/netty","owner":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Scottmitch/netty","description":"Netty project - an event-driven asynchronous network application framework","fork":true,"url":"https://api.github.com/repos/Scottmitch/netty","forks_url":"https://api.github.com/repos/Scottmitch/netty/forks","keys_url":"https://api.github.com/repos/Scottmitch/netty/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Scottmitch/netty/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Scottmitch/netty/teams","hooks_url":"https://api.github.com/repos/Scottmitch/netty/hooks","issue_events_url":"https://api.github.com/repos/Scottmitch/netty/issues/events{/number}","events_url":"https://api.github.com/repos/Scottmitch/netty/events","assignees_url":"https://api.github.com/repos/Scottmitch/netty/assignees{/user}","branches_url":"https://api.github.com/repos/Scottmitch/netty/branches{/branch}","tags_url":"https://api.github.com/repos/Scottmitch/netty/tags","blobs_url":"https://api.github.com/repos/Scottmitch/netty/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Scottmitch/netty/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Scottmitch/netty/git/refs{/sha}","trees_url":"https://api.github.com/repos/Scottmitch/netty/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Scottmitch/netty/statuses/{sha}","languages_url":"https://api.github.com/repos/Scottmitch/netty/languages","stargazers_url":"https://api.github.com/repos/Scottmitch/netty/stargazers","contributors_url":"https://api.github.com/repos/Scottmitch/netty/contributors","subscribers_url":"https://api.github.com/repos/Scottmitch/netty/subscribers","subscription_url":"https://api.github.com/repos/Scottmitch/netty/subscription","commits_url":"https://api.github.com/repos/Scottmitch/netty/commits{/sha}","git_commits_url":"https://api.github.com/repos/Scottmitch/netty/git/commits{/sha}","comments_url":"https://api.github.com/repos/Scottmitch/netty/comments{/number}","issue_comment_url":"https://api.github.com/repos/Scottmitch/netty/issues/comments{/number}","contents_url":"https://api.github.com/repos/Scottmitch/netty/contents/{+path}","compare_url":"https://api.github.com/repos/Scottmitch/netty/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Scottmitch/netty/merges","archive_url":"https://api.github.com/repos/Scottmitch/netty/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Scottmitch/netty/downloads","issues_url":"https://api.github.com/repos/Scottmitch/netty/issues{/number}","pulls_url":"https://api.github.com/repos/Scottmitch/netty/pulls{/number}","milestones_url":"https://api.github.com/repos/Scottmitch/netty/milestones{/number}","notifications_url":"https://api.github.com/repos/Scottmitch/netty/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Scottmitch/netty/labels{/name}","releases_url":"https://api.github.com/repos/Scottmitch/netty/releases{/id}","deployments_url":"https://api.github.com/repos/Scottmitch/netty/deployments","created_at":"2014-06-26T18:56:19Z","updated_at":"2016-02-08T18:45:50Z","pushed_at":"2016-06-23T22:39:11Z","git_url":"git://github.com/Scottmitch/netty.git","ssh_url":"git@github.com:Scottmitch/netty.git","clone_url":"https://github.com/Scottmitch/netty.git","svn_url":"https://github.com/Scottmitch/netty","homepage":"http://netty.io/","size":40977,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"netty:4.1","ref":"4.1","sha":"77c6d7a67249423a21cd8a8323133cb205f58710","user":{"login":"netty","id":473791,"avatar_url":"https://avatars.githubusercontent.com/u/473791?v=3","gravatar_id":"","url":"https://api.github.com/users/netty","html_url":"https://github.com/netty","followers_url":"https://api.github.com/users/netty/followers","following_url":"https://api.github.com/users/netty/following{/other_user}","gists_url":"https://api.github.com/users/netty/gists{/gist_id}","starred_url":"https://api.github.com/users/netty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netty/subscriptions","organizations_url":"https://api.github.com/users/netty/orgs","repos_url":"https://api.github.com/users/netty/repos","events_url":"https://api.github.com/users/netty/events{/privacy}","received_events_url":"https://api.github.com/users/netty/received_events","type":"Organization","site_admin":false},"repo":{"id":1064563,"name":"netty","full_name":"netty/netty","owner":{"login":"netty","id":473791,"avatar_url":"https://avatars.githubusercontent.com/u/473791?v=3","gravatar_id":"","url":"https://api.github.com/users/netty","html_url":"https://github.com/netty","followers_url":"https://api.github.com/users/netty/followers","following_url":"https://api.github.com/users/netty/following{/other_user}","gists_url":"https://api.github.com/users/netty/gists{/gist_id}","starred_url":"https://api.github.com/users/netty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netty/subscriptions","organizations_url":"https://api.github.com/users/netty/orgs","repos_url":"https://api.github.com/users/netty/repos","events_url":"https://api.github.com/users/netty/events{/privacy}","received_events_url":"https://api.github.com/users/netty/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/netty/netty","description":"Netty project - an event-driven asynchronous network application framework","fork":false,"url":"https://api.github.com/repos/netty/netty","forks_url":"https://api.github.com/repos/netty/netty/forks","keys_url":"https://api.github.com/repos/netty/netty/keys{/key_id}","collaborators_url":"https://api.github.com/repos/netty/netty/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/netty/netty/teams","hooks_url":"https://api.github.com/repos/netty/netty/hooks","issue_events_url":"https://api.github.com/repos/netty/netty/issues/events{/number}","events_url":"https://api.github.com/repos/netty/netty/events","assignees_url":"https://api.github.com/repos/netty/netty/assignees{/user}","branches_url":"https://api.github.com/repos/netty/netty/branches{/branch}","tags_url":"https://api.github.com/repos/netty/netty/tags","blobs_url":"https://api.github.com/repos/netty/netty/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/netty/netty/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/netty/netty/git/refs{/sha}","trees_url":"https://api.github.com/repos/netty/netty/git/trees{/sha}","statuses_url":"https://api.github.com/repos/netty/netty/statuses/{sha}","languages_url":"https://api.github.com/repos/netty/netty/languages","stargazers_url":"https://api.github.com/repos/netty/netty/stargazers","contributors_url":"https://api.github.com/repos/netty/netty/contributors","subscribers_url":"https://api.github.com/repos/netty/netty/subscribers","subscription_url":"https://api.github.com/repos/netty/netty/subscription","commits_url":"https://api.github.com/repos/netty/netty/commits{/sha}","git_commits_url":"https://api.github.com/repos/netty/netty/git/commits{/sha}","comments_url":"https://api.github.com/repos/netty/netty/comments{/number}","issue_comment_url":"https://api.github.com/repos/netty/netty/issues/comments{/number}","contents_url":"https://api.github.com/repos/netty/netty/contents/{+path}","compare_url":"https://api.github.com/repos/netty/netty/compare/{base}...{head}","merges_url":"https://api.github.com/repos/netty/netty/merges","archive_url":"https://api.github.com/repos/netty/netty/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/netty/netty/downloads","issues_url":"https://api.github.com/repos/netty/netty/issues{/number}","pulls_url":"https://api.github.com/repos/netty/netty/pulls{/number}","milestones_url":"https://api.github.com/repos/netty/netty/milestones{/number}","notifications_url":"https://api.github.com/repos/netty/netty/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/netty/netty/labels{/name}","releases_url":"https://api.github.com/repos/netty/netty/releases{/id}","deployments_url":"https://api.github.com/repos/netty/netty/deployments","created_at":"2010-11-09T09:22:21Z","updated_at":"2016-06-24T16:08:30Z","pushed_at":"2016-06-24T15:58:39Z","git_url":"git://github.com/netty/netty.git","ssh_url":"git@github.com:netty/netty.git","clone_url":"https://github.com/netty/netty.git","svn_url":"https://github.com/netty/netty","homepage":"http://netty.io/","size":69097,"stargazers_count":7156,"watchers_count":7156,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3646,"mirror_url":null,"open_issues_count":322,"forks":3646,"open_issues":322,"watchers":7156,"default_branch":"4.1"}},"_links":{"self":{"href":"https://api.github.com/repos/netty/netty/pulls/5446"},"html":{"href":"https://github.com/netty/netty/pull/5446"},"issue":{"href":"https://api.github.com/repos/netty/netty/issues/5446"},"comments":{"href":"https://api.github.com/repos/netty/netty/issues/5446/comments"},"review_comments":{"href":"https://api.github.com/repos/netty/netty/pulls/5446/comments"},"review_comment":{"href":"https://api.github.com/repos/netty/netty/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/netty/netty/pulls/5446/commits"},"statuses":{"href":"https://api.github.com/repos/netty/netty/statuses/b90e35f69caffa1b7322742b60621b41fc02650a"}}}}
{"actor":{"display_login":"Scottmitch"}}