Re: [BUG] minor: wrong handling of GIT_AUTHOR_DATE

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Hermann Gausterer <git-mailinglist@...>, Junio C Hamano <gitster@...>
Cc: Git Mailinglist <git@...>
Date: Saturday, August 16, 2008 - 7:03 pm

On Sat, 16 Aug 2008, Hermann Gausterer wrote:

Git uses a fairly odd date parsing library, and it turns out that 
917476713 +0200 is actually a perfectly valid date in the git format, 
because one thing git allows is the "seconds since epoch" one. So doing

	[torvalds@nehalem git]$ ./test-date "917476713 +0200"
	917476713 +0200 -> 917476713 +0200 -> Wed Jan 27 14:38:33 1999
	917476713 +0200 -> Wed Jan 27 14:38:33 1999

and it turns out that git will totally ignore any other format date when i 
sees this standard format (yes, that is literally the format that git uses 
internally).

So because git date parsing doesn't even really understand fractional 
seconds, and thus doesn't parse it, it will take the fraction, and if it 
was larger than 100000000, it will assume it's a seconds-since-epoch date.

Unlucky.

Anyway, something like this should fix it.

Junio: we might also make the code that actually parses the 
seconds-per-epoch thing only trigger if we haven't already seen a date (ie 
it might check for "tm->tm_year < 0" etc before accepting that seconds 
format).

		Linus

---
Subject: Ignore fractional seconds in date parsing
From: Linus Torvalds <torvads@linux-foundation.org>

.. otherwise a nanosecond resolution fractional second might be 
interpreted as a seconds-since-epoch date format string and overwrite the 
date we so carefully just parsed.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Noticed-by: Hermann Gausterer <git-mailinglist@mrq1.org>
---
 date.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/date.c b/date.c
index 35a5257..5e502da 100644
--- a/date.c
+++ b/date.c
@@ -363,6 +363,11 @@ static int match_multi_number(unsigned long num, char c, const char *date, char
 			tm->tm_hour = num;
 			tm->tm_min = num2;
 			tm->tm_sec = num3;
+
+			/* Ignore any possible fractional seconds */
+			if (*end == '.')
+				(void) strtol(end+1, &end, 10);
+
 			break;
 		}
 		return 0;
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[BUG] minor: wrong handling of GIT_AUTHOR_DATE, Hermann Gausterer, (Sat Aug 16, 4:53 pm)
Re: [BUG] minor: wrong handling of GIT_AUTHOR_DATE, Linus Torvalds, (Sat Aug 16, 7:03 pm)
Re: [BUG] minor: wrong handling of GIT_AUTHOR_DATE, Linus Torvalds, (Sat Aug 16, 7:17 pm)