diff options
author | David Turner <dturner@twosigma.com> | 2016-09-26 16:41:19 -0400 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2016-10-19 22:24:24 +0900 |
commit | e3468735111f26e4cdb4c249c257da52f4c3cffb (patch) | |
tree | 213c1ff0f07dd7252a6293211e5c431f866b1823 /org.eclipse.jgit | |
parent | ccc899773e903cae48816edc9ad3c564c161111d (diff) | |
download | jgit-e3468735111f26e4cdb4c249c257da52f4c3cffb.tar.gz jgit-e3468735111f26e4cdb4c249c257da52f4c3cffb.zip |
TreeFormatter: disallow empty filenames in trees
Git barfs on these (and they don't make any sense), so we certainly
shouldn't write them.
Change-Id: I3faf8554a05f0fd147be2e63fbe55987d3f88099
Signed-off-by: David Turner <dturner@twosigma.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit')
3 files changed, 31 insertions, 0 deletions
diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties index 2c721eabb6..5f420ab18f 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties @@ -367,6 +367,7 @@ invalidTagOption=Invalid tag option: {0} invalidTimeout=Invalid timeout: {0} invalidTimeUnitValue2=Invalid time unit value: {0}.{1}={2} invalidTimeUnitValue3=Invalid time unit value: {0}.{1}.{2}={3} +invalidTreeZeroLengthName=Cannot append a tree entry with zero-length name invalidURL=Invalid URL {0} invalidWildcards=Invalid wildcards {0} invalidRefSpec=Invalid refspec {0} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java index 956171b127..e920554a48 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java @@ -425,6 +425,7 @@ public class JGitText extends TranslationBundle { /***/ public String invalidTimeout; /***/ public String invalidTimeUnitValue2; /***/ public String invalidTimeUnitValue3; + /***/ public String invalidTreeZeroLengthName; /***/ public String invalidURL; /***/ public String invalidWildcards; /***/ public String invalidRefSpec; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TreeFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TreeFormatter.java index 065b8f46b6..777ce94aa0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TreeFormatter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TreeFormatter.java @@ -53,6 +53,7 @@ import static org.eclipse.jgit.lib.FileMode.TREE; import java.io.IOException; import org.eclipse.jgit.errors.CorruptObjectException; +import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.revwalk.RevBlob; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevTree; @@ -193,6 +194,34 @@ public class TreeFormatter { */ public void append(byte[] nameBuf, int namePos, int nameLen, FileMode mode, AnyObjectId id) { + append(nameBuf, namePos, nameLen, mode, id, false); + } + + /** + * Append any entry to the tree. + * + * @param nameBuf + * buffer holding the name of the entry. The name should be UTF-8 + * encoded, but file name encoding is not a well defined concept + * in Git. + * @param namePos + * first position within {@code nameBuf} of the name data. + * @param nameLen + * number of bytes from {@code nameBuf} to use as the name. + * @param mode + * mode describing the treatment of {@code id}. + * @param id + * the ObjectId to store in this entry. + * @param allowEmptyName + * allow an empty filename (creating a corrupt tree) + * @since 4.6 + */ + public void append(byte[] nameBuf, int namePos, int nameLen, FileMode mode, + AnyObjectId id, boolean allowEmptyName) { + if (nameLen == 0 && !allowEmptyName) { + throw new IllegalArgumentException( + JGitText.get().invalidTreeZeroLengthName); + } if (fmtBuf(nameBuf, namePos, nameLen, mode)) { id.copyRawTo(buf, ptr); ptr += OBJECT_ID_LENGTH; |