summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColby Ranger <cranger@google.com>2012-12-27 12:33:13 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2012-12-27 12:33:13 -0500
commit5a3d35e9e2f1df0726c460f3a629c5e56cfed8e8 (patch)
tree23db6a30888723151dba29d76c2bba8f3877b2fd
parent7314b6c2c03ea8fec02810821639a2c8bba162a8 (diff)
parent51beee5568b7c44b01240b96c0d4d81e10362fae (diff)
downloadjgit-5a3d35e9e2f1df0726c460f3a629c5e56cfed8e8.tar.gz
jgit-5a3d35e9e2f1df0726c460f3a629c5e56cfed8e8.zip
Merge "Enforce max memory for DeltaWindow."
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/DeltaWindow.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/DeltaWindow.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/DeltaWindow.java
index c51cafcbf2..b440774bc6 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/DeltaWindow.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/DeltaWindow.java
@@ -164,6 +164,14 @@ class DeltaWindow {
return DeltaIndex.estimateIndexSize(ent.getWeight());
}
+ private static long estimateIndexSize(DeltaWindowEntry ent) {
+ if (ent.buffer == null)
+ return estimateSize(ent.object);
+
+ int len = ent.buffer.length;
+ return DeltaIndex.estimateIndexSize(len) - len;
+ }
+
private void clear(DeltaWindowEntry ent) {
if (ent.index != null)
loaded -= ent.index.getIndexSize();
@@ -420,6 +428,8 @@ class DeltaWindow {
IOException, LargeObjectException {
DeltaIndex idx = ent.index;
if (idx == null) {
+ checkLoadable(ent, estimateIndexSize(ent));
+
try {
idx = new DeltaIndex(buffer(ent));
} catch (OutOfMemoryError noMemory) {
@@ -439,6 +449,8 @@ class DeltaWindow {
IncorrectObjectTypeException, IOException, LargeObjectException {
byte[] buf = ent.buffer;
if (buf == null) {
+ checkLoadable(ent, ent.size());
+
buf = PackWriter.buffer(config, reader, ent.object);
if (0 < maxMemory)
loaded += buf.length;
@@ -447,6 +459,18 @@ class DeltaWindow {
return buf;
}
+ private void checkLoadable(DeltaWindowEntry ent, long need) {
+ int tail = next(resSlot);
+ while (maxMemory < loaded + need) {
+ DeltaWindowEntry cur = window[tail];
+ clear(cur);
+ if (cur == ent)
+ throw new LargeObjectException.ExceedsLimit(
+ maxMemory, loaded + need);
+ tail = next(tail);
+ }
+ }
+
private Deflater deflater() {
if (deflater == null)
deflater = new Deflater(config.getCompressionLevel());