git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[EGIT PATCH] Committer, author and tagger time should not be parsed as 32 bit signed int

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
Dec 17, 2008, 22:32 UTC
Message-ID
<1229553172-2038-1-git-send-email-robin.rosenberg@dewire.com>
In-Reply-To
<200812172328.07371.robin.rosenberg.lists@dewire.com>

If not dates past 2038 will be parsed the wrong way when parsed into a RevCommit or RevTag object.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/jgit/util/RawParseUtils.java   |   58 +++++++++++++++++++-
 1 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java
index 55a3001..74fe506 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java
@@ -135,7 +135,7 @@ public static int formatBase10(final byte[] b, int o, int value) {
 	}
 
 	/**
-	 * Parse a base 10 numeric from a sequence of ASCII digits.
+	 * Parse a base 10 numeric from a sequence of ASCII digits into an int.
 	 * <p>
 	 * Digit sequences can begin with an optional run of spaces before the
 	 * sequence, and may start with a '+' or a '-' to indicate sign position.
@@ -189,6 +189,60 @@ public static final int parseBase10(final byte[] b, int ptr,
 	}
 
 	/**
+	 * Parse a base 10 numeric from a sequence of ASCII digits into a long.
+	 * <p>
+	 * Digit sequences can begin with an optional run of spaces before the
+	 * sequence, and may start with a '+' or a '-' to indicate sign position.
+	 * Any other characters will cause the method to stop and return the current
+	 * result to the caller.
+	 * 
+	 * @param b
+	 *            buffer to scan.
+	 * @param ptr
+	 *            position within buffer to start parsing digits at.
+	 * @param ptrResult
+	 *            optional location to return the new ptr value through. If null
+	 *            the ptr value will be discarded.
+	 * @return the value at this location; 0 if the location is not a valid
+	 *         numeric.
+	 */
+	public static final long parseLongBase10(final byte[] b, int ptr,
+			final MutableInteger ptrResult) {
+		long r = 0;
+		int sign = 0;
+		try {
+			final int sz = b.length;
+			while (ptr < sz && b[ptr] == ' ')
+				ptr++;
+			if (ptr >= sz)
+				return 0;
+
+			switch (b[ptr]) {
+			case '-':
+				sign = -1;
+				ptr++;
+				break;
+			case '+':
+				ptr++;
+				break;
+			}
+
+			while (ptr < sz) {
+				final byte v = digits[b[ptr]];
+				if (v < 0)
+					break;
+				r = (r * 10) + v;
+				ptr++;
+			}
+		} catch (ArrayIndexOutOfBoundsException e) {
+			// Not a valid digit.
+		}
+		if (ptrResult != null)
+			ptrResult.value = ptr;
+		return sign < 0 ? -r : r;
+	}
+
+	/**
 	 * Parse a Git style timezone string.
 	 * <p>
 	 * The sequence "-0315" will be parsed as the numeric value -195, as the
@@ -414,7 +468,7 @@ public static PersonIdent parsePersonIdent(final byte[] raw, final int nameB) {
 		final String email = decode(cs, raw, emailB, emailE - 1);
 
 		final MutableInteger ptrout = new MutableInteger();
-		final int when = parseBase10(raw, emailE + 1, ptrout);
+		final long when = parseLongBase10(raw, emailE + 1, ptrout);
 		final int tz = parseTimeZoneOffset(raw, ptrout.value);
 
 		return new PersonIdent(name, email, when * 1000L, tz);
-- 
1.6.0.3.640.g6331a
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 7 of 9 in “*** SUBJECT HERE ***”
  1. 0/2 *** SUBJECT HERE ***Robin Rosenberg, Dec 17, 2008
  2. 1/2 Revert "Fix commit id in egit test T0001_ConnectProviderOperationTest"Robin Rosenberg, Dec 17, 2008
  3. 2/2 Fixed an old failed EGit unit test.Robin Rosenberg, Dec 17, 2008
  4. Shawn O. PearceDec 17, 2008
  5. Robin RosenbergDec 17, 2008
  6. Shawn O. PearceDec 17, 2008
  7. Committer, author and tagger time should not be parsed as 32 bit signed intRobin Rosenberg, Dec 17, 2008
  8. Shawn O. PearceDec 17, 2008
  9. Robin RosenbergDec 18, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.