From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [JGIT PATCH 1/2] Fix the UnpackedObjectCache hash function to prevent overflow
Date: Tue, 30 Sep 2008 00:47:50 -0700 [thread overview]
Message-ID: <1222760871-58768-1-git-send-email-spearce@spearce.org> (raw)
Sometimes we got negative array indexes inside of the cache due
to WindowedFile.hash having a negative value assigned by the JVM.
We now use only the lower 8 bits as the cache is fixed to at most
256 entries.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../org/spearce/jgit/lib/UnpackedObjectCache.java | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectCache.java
index 03cf674..ee6a680 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectCache.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectCache.java
@@ -48,9 +48,9 @@
private static int hash(final WindowedFile pack, final long position) {
int h = pack.hash + (int) position;
- h += h >> 16;
- h += h >> 8;
- return h % CACHE_SZ;
+ h += h >>> 16;
+ h += h >>> 8;
+ return h & (CACHE_SZ - 1);
}
private static int maxByteCount;
--
1.6.0.2.463.g7f0eb
next reply other threads:[~2008-09-30 7:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-30 7:47 Shawn O. Pearce [this message]
2008-09-30 7:47 ` [JGIT PATCH 2/2] ObjectId: Convert StringIndexOutOfBounds to IllegalArgumentException Shawn O. Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1222760871-58768-1-git-send-email-spearce@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=robin.rosenberg@dewire.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).