{"thread":{"id":"15718","subject":"[JGIT PATCH 1/2] Fix the UnpackedObjectCache hash function to prevent overflow","startedAt":"2008-09-30T07:47:50Z","lastAt":"2008-09-30T07:47:51Z","messageCount":2,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"91899","messageId":"1222760871-58768-1-git-send-email-spearce@spearce.org","threadId":"15718","inReplyTo":null,"subject":"[JGIT PATCH 1/2] Fix the UnpackedObjectCache hash function to prevent overflow","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-30T07:47:50Z","receivedAt":"2008-09-30T07:47:50Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Sometimes we got negative array indexes inside of the cache due\nto WindowedFile.hash having a negative value assigned by the JVM.\nWe now use only the lower 8 bits as the cache is fixed to at most\n256 entries.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../org/spearce/jgit/lib/UnpackedObjectCache.java  |    6 +++---\n 1 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectCache.java\nindex 03cf674..ee6a680 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectCache.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectCache.java\n@@ -48,9 +48,9 @@\n \n \tprivate static int hash(final WindowedFile pack, final long position) {\n \t\tint h = pack.hash + (int) position;\n-\t\th += h >> 16;\n-\t\th += h >> 8;\n-\t\treturn h % CACHE_SZ;\n+\t\th += h >>> 16;\n+\t\th += h >>> 8;\n+\t\treturn h & (CACHE_SZ - 1);\n \t}\n \n \tprivate static int maxByteCount;\n-- \n1.6.0.2.463.g7f0eb\n"},{"id":"91900","messageId":"1222760871-58768-2-git-send-email-spearce@spearce.org","threadId":"15718","inReplyTo":"1222760871-58768-1-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 2/2] ObjectId: Convert StringIndexOutOfBounds to IllegalArgumentException","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-30T07:47:51Z","receivedAt":"2008-09-30T07:47:51Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"If parsing an ObjectId fromString fails because the string is too short\nwe don't want to throw StringIndexOutOfBoundsException with a trace that\nleads back to the error handling code; instead we should throw what the\ncaller expects us to throw, which is IllegalArgumentException.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../src/org/spearce/jgit/lib/MutableObjectId.java  |    2 ++\n 1 files changed, 2 insertions(+), 0 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/MutableObjectId.java b/org.spearce.jgit/src/org/spearce/jgit/lib/MutableObjectId.java\nindex f88d8cb..5b16345 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/MutableObjectId.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/MutableObjectId.java\n@@ -161,6 +161,8 @@ private void fromHexString(final byte[] bs, int p) {\n \t\t\t\tthrow new IllegalArgumentException(\"Invalid id: \" + str);\n \t\t\t} catch (UnsupportedEncodingException e2) {\n \t\t\t\tthrow new IllegalArgumentException(\"Invalid id\");\n+\t\t\t} catch (StringIndexOutOfBoundsException e2) {\n+\t\t\t\tthrow new IllegalArgumentException(\"Invalid id\");\n \t\t\t}\n \t\t}\n \t}\n-- \n1.6.0.2.463.g7f0eb\n"}]}