From avg@topspin.kiev.ua  Wed May 24 12:13:26 2006
Return-Path: <avg@topspin.kiev.ua>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 8C18216A42C
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 24 May 2006 12:13:26 +0000 (UTC)
	(envelope-from avg@topspin.kiev.ua)
Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 8FFC543D4C
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 24 May 2006 12:13:25 +0000 (GMT)
	(envelope-from avg@topspin.kiev.ua)
Received: from oddity.topspin.kiev.ua (oddity-e.topspin.kiev.ua [212.40.38.87])
	by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id PAA21175
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 24 May 2006 15:13:23 +0300 (EEST)
	(envelope-from avg@topspin.kiev.ua)
Received: from oddity.topspin.kiev.ua (localhost [127.0.0.1])
	by oddity.topspin.kiev.ua (8.13.6/8.13.6) with ESMTP id k4OCDN11004370
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 24 May 2006 15:13:23 +0300 (EEST)
	(envelope-from avg@oddity.topspin.kiev.ua)
Received: (from avg@localhost)
	by oddity.topspin.kiev.ua (8.13.6/8.13.6/Submit) id k4OCDNWh004369;
	Wed, 24 May 2006 15:13:23 +0300 (EEST)
	(envelope-from avg)
Message-Id: <200605241213.k4OCDNWh004369@oddity.topspin.kiev.ua>
Date: Wed, 24 May 2006 15:13:23 +0300 (EEST)
From: Andriy Gapon <avg@topspin.kiev.ua>
Reply-To: Andriy Gapon <avg@topspin.kiev.ua>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: fs/udf: incorrect timestamps
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         97786
>Category:       kern
>Synopsis:       [udf] [patch] fs/udf: incorrect timestamps
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    markus
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 24 12:20:20 GMT 2006
>Closed-Date:    Sun Mar 22 02:18:10 UTC 2009
>Last-Modified:  Sun Mar 22 02:18:10 UTC 2009
>Originator:     Andriy Gapon
>Release:        FreeBSD 6.1-RELEASE i386
>Organization:
>Environment:
System: FreeBSD 6.1-RELEASE i386


	
>Description:
Thanks to Bruce Evans for discovering this bug and sharing his patch.
To the best of my knowledge this was not filed as a PR before, so I am
doing it now to share the knowledge with community.

Badically, existing code doesn't take into account that day- and month-
numbering starts with 1, not zero. Month number is not validated.
Also, for timestamps before 2000 it can report only three values
(Jan 1 1980, Jan 1 1990, Jan 1 2000), becaus of a bug in "fast-forwarding"
optimization.

>How-To-Repeat:
	
>Fix:

	

--- datetime.patch begins here ---
--- sys/fs/udf/udf_vnops.c	23 Jun 2004 21:49:03 -0000    1.37
+++ sys/fs/udf/udf_vnops.c	19 Apr 2005 06:42:17 -0000
@@ -265,7 +268,11 @@
 	t->tv_nsec = 0;

-	/* DirectCD seems to like using bogus year values */
+	/*
+	 * DirectCD seems to like using bogus year values.
+	 * Distrust time->month especially, since it will be used for an
+	 * array index.
+	 */
 	year = le16toh(time->year);
-	if (year < 1970) {
+	if (year < 1970 || time->month > 12) {
 		t->tv_sec = 0;
 		return;
@@ -276,19 +283,12 @@
 	t->tv_sec += time->minute * 60;
 	t->tv_sec += time->hour * 3600;
-	t->tv_sec += time->day * 3600 * 24;
+	t->tv_sec += (time->day - 1) * 3600 * 24;
 
 	/* Calculate the month */
 	lpyear = udf_isaleapyear(year);
 	for (i = 1; i < time->month; i++)
-		t->tv_sec += mon_lens[lpyear][i] * 3600 * 24;
+		t->tv_sec += mon_lens[lpyear][i - 1] * 3600 * 24;
 
-	/* Speed up the calculation */
-	if (year > 1979)
-		t->tv_sec += 315532800;
-	if (year > 1989)
-		t->tv_sec += 315619200;
-	if (year > 1999)
-		t->tv_sec += 315532800;
-	for (i = 2000; i < year; i++) {
+	for (i = 1970; i < year; i++) {
 		daysinyear = udf_isaleapyear(i) + 365 ;
 		t->tv_sec += daysinyear * 3600 * 24;
--- datetime.patch ends here ---


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: markus 
State-Changed-When: Fri May 16 22:32:26 UTC 2008 
State-Changed-Why:  
A different version has been committed, which fixes the timestamp calculations, 
calculates the missing microseconds part, fixes an endian problem and speeds up 
the calculations, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=97786 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/97786: commit references a PR
Date: Fri, 16 May 2008 22:31:24 +0000 (UTC)

 markus      2008-05-16 22:31:17 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/fs/udf           udf_vnops.c 
   Log:
   Fix and speedup timestamp calculations which is roughly based on the patch in
   the mentioned PR:
   
   - bounds check time->month as it is used as an array index
   - fix usage of time->month as array index (month is 1-12)
   - fix calculation based on time->day (day is 1-31)
   - fix the speedup code as it doesn't calculate correct timestamps before
     the year 2000 and reduce the number of calculation in the year-by-year code
   - speedup month calculations by replacing the array content with cumulative
     values
   - add microseconds calculation
   - fix an endian problem
   
   PR:             kern/97786
   Submitted by:   Andriy Gapon <avg@topspin.kiev.ua>
   Reviewed by:    scottl (earlier version)
   Approved by:    emax (mentor)
   MFC after:      1 week
   
   Revision  Changes    Path
   1.69      +34 -22    src/sys/fs/udf/udf_vnops.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: Christopher Key <cjk32@cam.ac.uk>
To: bug-followup@FreeBSD.org, avg@topspin.kiev.ua
Cc:  
Subject: Re: kern/97786: [udf] [patch] fs/udf: incorrect timestamps
Date: Thu, 19 Mar 2009 20:12:39 +0000

 This is a multi-part message in MIME format.
 --------------030203030007060208040602
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 The applied patch is calculating microseconds instead of nanoseconds,
 new patch attached.
 
 Also, is there any chance of getting this MFCed?
 
 
 --------------030203030007060208040602
 Content-Type: text/plain;
  name="udf-nsec.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="udf-nsec.patch"
 
 Index: sys/fs/udf/udf_vnops.c
 ===================================================================
 --- sys/fs/udf/udf_vnops.c	(revision 190096)
 +++ sys/fs/udf/udf_vnops.c	(working copy)
 @@ -260,9 +260,10 @@
  		daysinyear += udf_isaleapyear(i);
  	t->tv_sec += daysinyear * 3600 * 24;
  
 -	/* Calculate microseconds */
 -	t->tv_nsec = time->centisec * 10000 + time->hund_usec * 100 +
 -	    time->usec;
 +	/* Calculate nanoseconds */
 +	t->tv_nsec = time->centisec * 100 * 100 * 1000 +
 +	    time->hund_usec * 100 * 1000 + 
 +	    time->usec * 1000;
  
  	/*
  	 * Calculate the time zone.  The timezone is 12 bit signed 2's
 
 --------------030203030007060208040602--
State-Changed-From-To: closed->open 
State-Changed-By: linimon 
State-Changed-When: Fri Mar 20 00:17:42 UTC 2009 
State-Changed-Why:  
New patch received.  Notify committer.  (Note: also needs MFC?) 


Responsible-Changed-From-To: freebsd-bugs->markus 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Mar 20 00:17:42 UTC 2009 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=97786 
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Sun Mar 22 02:15:33 UTC 2009 
State-Changed-Why:  
Apparently the new patch was already incorporated as well. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=97786 
>Unformatted:
