|
|
@ -341,48 +341,56 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase { |
|
|
|
String... path) throws GitAPIException, IOException { |
|
|
|
String... path) throws GitAPIException, IOException { |
|
|
|
try (Git git = new Git(db); |
|
|
|
try (Git git = new Git(db); |
|
|
|
RevWalk revWalk = new RevWalk(git.getRepository())) { |
|
|
|
RevWalk revWalk = new RevWalk(git.getRepository())) { |
|
|
|
ObjectInserter newObjectInserter; |
|
|
|
ObjectId blobId; |
|
|
|
newObjectInserter = git.getRepository().newObjectInserter(); |
|
|
|
try (ObjectInserter newObjectInserter = git.getRepository() |
|
|
|
ObjectId blobId = newObjectInserter.insert(Constants.OBJ_BLOB, |
|
|
|
.newObjectInserter()) { |
|
|
|
|
|
|
|
blobId = newObjectInserter.insert(Constants.OBJ_BLOB, |
|
|
|
"data".getBytes(UTF_8)); |
|
|
|
"data".getBytes(UTF_8)); |
|
|
|
newObjectInserter = git.getRepository().newObjectInserter(); |
|
|
|
} |
|
|
|
FileMode mode = FileMode.REGULAR_FILE; |
|
|
|
FileMode mode = FileMode.REGULAR_FILE; |
|
|
|
ObjectId insertId = blobId; |
|
|
|
ObjectId insertId = blobId; |
|
|
|
|
|
|
|
try (ObjectInserter newObjectInserter = git.getRepository() |
|
|
|
|
|
|
|
.newObjectInserter()) { |
|
|
|
for (int i = path.length - 1; i >= 0; --i) { |
|
|
|
for (int i = path.length - 1; i >= 0; --i) { |
|
|
|
TreeFormatter treeFormatter = new TreeFormatter(); |
|
|
|
TreeFormatter treeFormatter = new TreeFormatter(); |
|
|
|
treeFormatter.append("goodpath", mode, insertId); |
|
|
|
treeFormatter.append("goodpath", mode, insertId); |
|
|
|
insertId = newObjectInserter.insert(treeFormatter); |
|
|
|
insertId = newObjectInserter.insert(treeFormatter); |
|
|
|
mode = FileMode.TREE; |
|
|
|
mode = FileMode.TREE; |
|
|
|
} |
|
|
|
} |
|
|
|
newObjectInserter = git.getRepository().newObjectInserter(); |
|
|
|
} |
|
|
|
|
|
|
|
ObjectId firstCommitId; |
|
|
|
|
|
|
|
try (ObjectInserter newObjectInserter = git.getRepository() |
|
|
|
|
|
|
|
.newObjectInserter()) { |
|
|
|
CommitBuilder commitBuilder = new CommitBuilder(); |
|
|
|
CommitBuilder commitBuilder = new CommitBuilder(); |
|
|
|
commitBuilder.setAuthor(author); |
|
|
|
commitBuilder.setAuthor(author); |
|
|
|
commitBuilder.setCommitter(committer); |
|
|
|
commitBuilder.setCommitter(committer); |
|
|
|
commitBuilder.setMessage("foo#1"); |
|
|
|
commitBuilder.setMessage("foo#1"); |
|
|
|
commitBuilder.setTreeId(insertId); |
|
|
|
commitBuilder.setTreeId(insertId); |
|
|
|
ObjectId firstCommitId = newObjectInserter.insert(commitBuilder); |
|
|
|
firstCommitId = newObjectInserter.insert(commitBuilder); |
|
|
|
|
|
|
|
} |
|
|
|
newObjectInserter = git.getRepository().newObjectInserter(); |
|
|
|
ObjectId commitId; |
|
|
|
|
|
|
|
try (ObjectInserter newObjectInserter = git.getRepository() |
|
|
|
|
|
|
|
.newObjectInserter()) { |
|
|
|
mode = FileMode.REGULAR_FILE; |
|
|
|
mode = FileMode.REGULAR_FILE; |
|
|
|
insertId = blobId; |
|
|
|
insertId = blobId; |
|
|
|
for (int i = path.length - 1; i >= 0; --i) { |
|
|
|
for (int i = path.length - 1; i >= 0; --i) { |
|
|
|
TreeFormatter treeFormatter = new TreeFormatter(); |
|
|
|
TreeFormatter treeFormatter = new TreeFormatter(); |
|
|
|
treeFormatter.append(path[i].getBytes(UTF_8), 0, |
|
|
|
treeFormatter.append(path[i].getBytes(UTF_8), 0, |
|
|
|
path[i].getBytes(UTF_8).length, |
|
|
|
path[i].getBytes(UTF_8).length, mode, insertId, |
|
|
|
mode, insertId, true); |
|
|
|
true); |
|
|
|
insertId = newObjectInserter.insert(treeFormatter); |
|
|
|
insertId = newObjectInserter.insert(treeFormatter); |
|
|
|
mode = FileMode.TREE; |
|
|
|
mode = FileMode.TREE; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Create another commit
|
|
|
|
// Create another commit
|
|
|
|
commitBuilder = new CommitBuilder(); |
|
|
|
CommitBuilder commitBuilder = new CommitBuilder(); |
|
|
|
commitBuilder.setAuthor(author); |
|
|
|
commitBuilder.setAuthor(author); |
|
|
|
commitBuilder.setCommitter(committer); |
|
|
|
commitBuilder.setCommitter(committer); |
|
|
|
commitBuilder.setMessage("foo#2"); |
|
|
|
commitBuilder.setMessage("foo#2"); |
|
|
|
commitBuilder.setTreeId(insertId); |
|
|
|
commitBuilder.setTreeId(insertId); |
|
|
|
commitBuilder.setParentId(firstCommitId); |
|
|
|
commitBuilder.setParentId(firstCommitId); |
|
|
|
ObjectId commitId = newObjectInserter.insert(commitBuilder); |
|
|
|
commitId = newObjectInserter.insert(commitBuilder); |
|
|
|
|
|
|
|
} |
|
|
|
if (!secondCheckout) |
|
|
|
if (!secondCheckout) |
|
|
|
git.checkout().setStartPoint(revWalk.parseCommit(firstCommitId)) |
|
|
|
git.checkout().setStartPoint(revWalk.parseCommit(firstCommitId)) |
|
|
|
.setName("refs/heads/master").setCreateBranch(true).call(); |
|
|
|
.setName("refs/heads/master").setCreateBranch(true).call(); |
|
|
|