summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java41
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java21
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java4
4 files changed, 69 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
index c6578ccfae..274757d95d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
@@ -121,6 +121,42 @@ public class ObjectCheckerTest {
}
@Test
+ public void testCommitCorruptAuthor() throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ b.append("tree be9bfa841874ccc9f2ef7c48d0c76226f89b7189\n");
+ b.append("author b <b@c> <b@c> 0 +0000\n");
+ b.append("committer <> 0 +0000\n");
+
+ byte[] data = Constants.encodeASCII(b.toString());
+ try {
+ checker.checkCommit(data);
+ fail("Did not catch corrupt object");
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid author", e.getMessage());
+ }
+ checker.setAllowInvalidPersonIdent(true);
+ checker.checkCommit(data);
+ }
+
+ @Test
+ public void testCommitCorruptCommitter() throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ b.append("tree be9bfa841874ccc9f2ef7c48d0c76226f89b7189\n");
+ b.append("author <> 0 +0000\n");
+ b.append("committer b <b@c> <b@c> 0 +0000\n");
+
+ byte[] data = Constants.encodeASCII(b.toString());
+ try {
+ checker.checkCommit(data);
+ fail("Did not catch corrupt object");
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid committer", e.getMessage());
+ }
+ checker.setAllowInvalidPersonIdent(true);
+ checker.checkCommit(data);
+ }
+
+ @Test
public void testValidCommit1Parent() throws CorruptObjectException {
final StringBuilder b = new StringBuilder();
@@ -940,7 +976,8 @@ public class ObjectCheckerTest {
}
@Test
- public void testInvalidTagInvalidTaggerHeader1() {
+ public void testInvalidTagInvalidTaggerHeader1()
+ throws CorruptObjectException {
final StringBuilder b = new StringBuilder();
b.append("object ");
@@ -958,6 +995,8 @@ public class ObjectCheckerTest {
} catch (CorruptObjectException e) {
assertEquals("invalid tagger", e.getMessage());
}
+ checker.setAllowInvalidPersonIdent(true);
+ checker.checkTag(data);
}
@Test
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java
index 8435c9a64b..359b592952 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java
@@ -104,6 +104,8 @@ public class ObjectChecker {
private final MutableInteger ptrout = new MutableInteger();
private boolean allowZeroMode;
+
+ private boolean allowInvalidPersonIdent;
private boolean windows;
private boolean macosx;
@@ -125,6 +127,22 @@ public class ObjectChecker {
}
/**
+ * Enable accepting invalid author, committer and tagger identities.
+ * <p>
+ * Some broken Git versions/libraries allowed users to create commits and
+ * tags with invalid formatting between the name, email and timestamp.
+ *
+ * @param allow
+ * if true accept invalid person identity strings.
+ * @return {@code this}.
+ * @since 4.0
+ */
+ public ObjectChecker setAllowInvalidPersonIdent(boolean allow) {
+ allowInvalidPersonIdent = allow;
+ return this;
+ }
+
+ /**
* Restrict trees to only names legal on Windows platforms.
* <p>
* Also rejects any mixed case forms of reserved names ({@code .git}).
@@ -198,6 +216,9 @@ public class ObjectChecker {
}
private int personIdent(final byte[] raw, int ptr) {
+ if (allowInvalidPersonIdent)
+ return nextLF(raw, ptr) - 1;
+
final int emailB = nextLF(raw, ptr, '<');
if (emailB == ptr || raw[emailB - 1] != '<')
return -1;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
index b7a599bad5..cf1d92e8e8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
@@ -289,6 +289,7 @@ public abstract class BaseReceivePack {
final boolean checkReceivedObjects;
final boolean allowLeadingZeroFileMode;
+ final boolean allowInvalidPersonIdent;
final boolean safeForWindows;
final boolean safeForMacOS;
@@ -306,6 +307,8 @@ public abstract class BaseReceivePack {
config.getBoolean("transfer", "fsckobjects", false)); //$NON-NLS-1$ //$NON-NLS-2$
allowLeadingZeroFileMode = checkReceivedObjects
&& config.getBoolean("fsck", "allowLeadingZeroFileMode", false); //$NON-NLS-1$ //$NON-NLS-2$
+ allowInvalidPersonIdent = checkReceivedObjects
+ && config.getBoolean("fsck", "allowInvalidPersonIdent", false); //$NON-NLS-1$ //$NON-NLS-2$
safeForWindows = checkReceivedObjects
&& config.getBoolean("fsck", "safeForWindows", false); //$NON-NLS-1$ //$NON-NLS-2$
safeForMacOS = checkReceivedObjects
@@ -326,6 +329,7 @@ public abstract class BaseReceivePack {
return null;
return new ObjectChecker()
.setAllowLeadingZeroFileMode(allowLeadingZeroFileMode)
+ .setAllowInvalidPersonIdent(allowInvalidPersonIdent)
.setSafeForWindows(safeForWindows)
.setSafeForMacOS(safeForMacOS);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
index 1de91a57ef..60043fff76 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
@@ -67,6 +67,7 @@ public class TransferConfig {
private final boolean checkReceivedObjects;
private final boolean allowLeadingZeroFileMode;
+ private final boolean allowInvalidPersonIdent;
private final boolean safeForWindows;
private final boolean safeForMacOS;
private final boolean allowTipSha1InWant;
@@ -82,6 +83,8 @@ public class TransferConfig {
rc.getBoolean("transfer", "fsckobjects", false)); //$NON-NLS-1$ //$NON-NLS-2$
allowLeadingZeroFileMode = checkReceivedObjects
&& rc.getBoolean("fsck", "allowLeadingZeroFileMode", false); //$NON-NLS-1$ //$NON-NLS-2$
+ allowInvalidPersonIdent = checkReceivedObjects
+ && rc.getBoolean("fsck", "allowInvalidPersonIdent", false); //$NON-NLS-1$ //$NON-NLS-2$
safeForWindows = checkReceivedObjects
&& rc.getBoolean("fsck", "safeForWindows", //$NON-NLS-1$ //$NON-NLS-2$
SystemReader.getInstance().isWindows());
@@ -113,6 +116,7 @@ public class TransferConfig {
return null;
return new ObjectChecker()
.setAllowLeadingZeroFileMode(allowLeadingZeroFileMode)
+ .setAllowInvalidPersonIdent(allowInvalidPersonIdent)
.setSafeForWindows(safeForWindows)
.setSafeForMacOS(safeForMacOS);
}