summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2016-08-25 22:45:31 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2016-08-25 22:45:33 -0400
commit3b64c09ac48ef30b0ce5867a01cbbd62a5434df9 (patch)
tree1f1a1ea35273333eecfe6ff1192a5d48b991b315
parentc29363046dae6eb7d469cd86de0ba32c2ea9eef5 (diff)
parent9ae7d493c45c0cd7243209e004901308816abaf3 (diff)
downloadjgit-3b64c09ac48ef30b0ce5867a01cbbd62a5434df9.tar.gz
jgit-3b64c09ac48ef30b0ce5867a01cbbd62a5434df9.zip
Merge "DfsReader: check object type during open"
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java17
2 files changed, 17 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java
index c57c41741f..a5e920a75e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java
@@ -69,6 +69,7 @@ import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
import org.eclipse.jgit.errors.CorruptObjectException;
+import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.LargeObjectException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.internal.storage.file.PackIndex;
@@ -570,6 +571,9 @@ public class DfsInserter extends ObjectInserter {
if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA)
throw new IOException(MessageFormat.format(
DfsText.get().cannotReadBackDelta, Integer.toString(type)));
+ if (typeHint != OBJ_ANY && type != typeHint) {
+ throw new IncorrectObjectTypeException(objectId.copy(), typeHint);
+ }
long sz = c & 0x0f;
int ptr = 1;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java
index cc2f350034..2f61dea0d5 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java
@@ -222,20 +222,21 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
ObjectLoader ldr;
if (last != null) {
ldr = last.get(this, objectId);
- if (ldr != null)
- return ldr;
+ if (ldr != null) {
+ return checkType(ldr, objectId, typeHint);
+ }
}
PackList packList = db.getPackList();
boolean noGarbage = avoidUnreachable;
ldr = openImpl(packList, objectId, noGarbage);
if (ldr != null) {
- return ldr;
+ return checkType(ldr, objectId, typeHint);
}
if (packList.dirty()) {
ldr = openImpl(db.scanPacks(packList), objectId, noGarbage);
if (ldr != null) {
- return ldr;
+ return checkType(ldr, objectId, typeHint);
}
}
@@ -245,6 +246,14 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
throw new MissingObjectException(objectId.copy(), typeHint);
}
+ private static ObjectLoader checkType(ObjectLoader ldr, AnyObjectId id,
+ int typeHint) throws IncorrectObjectTypeException {
+ if (typeHint != OBJ_ANY && ldr.getType() != typeHint) {
+ throw new IncorrectObjectTypeException(id.copy(), typeHint);
+ }
+ return ldr;
+ }
+
private ObjectLoader openImpl(PackList packList, AnyObjectId objectId,
boolean noGarbage) throws IOException {
for (DfsPackFile pack : packList.packs) {