[Mono-bugs] [Bug 76328][Wis] New - XmlConvert.ToTimeSpan hangs on "PT0.1S"

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Oct 4 13:51:33 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by awaddell at fnfr.com.

http://bugzilla.ximian.com/show_bug.cgi?id=76328

--- shadow/76328	2005-10-04 13:51:33.000000000 -0400
+++ shadow/76328.tmp.18650	2005-10-04 13:51:33.000000000 -0400
@@ -0,0 +1,155 @@
+Bug#: 76328
+Product: Mono: Class Libraries
+Version: unspecified
+OS: Red Hat 8.0
+OS Details: Linux AWLNX.fnfr.com 2.4.21-20.EL #1 Wed Aug 18 20:58:25 EDT 2004 i686 i686 i386 GNU/Linux
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: Sys.XML
+AssignedTo: atsushi at ximian.com                            
+ReportedBy: awaddell at fnfr.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: XmlConvert.ToTimeSpan hangs on "PT0.1S"
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+XmlConvert.ToTimeSpan assumes that millisecons are always expressed as 3
+digits past the decimal place.  .NET encodes a 100ms TimeSpan as "PT0.1S"
+which will case the Mono XmlConvert.ToTimeSpan to hang in an infinite loop.
+
+The following code:
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Xml;
+
+namespace XMLtest
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+
+            int milliseconds;
+            string timespan;
+
+            milliseconds = 100;
+           
+Console.WriteLine("XmlConvert.ToString(TimeSpan.FromMilliseconds(" +
+milliseconds + ")) returns '" +
+XmlConvert.ToString(TimeSpan.FromMilliseconds(milliseconds)) + "'");
+            milliseconds = 10;
+           
+Console.WriteLine("XmlConvert.ToString(TimeSpan.FromMilliseconds(" +
+milliseconds + ")) returns '" +
+XmlConvert.ToString(TimeSpan.FromMilliseconds(milliseconds)) + "'");
+            milliseconds = 1;
+           
+Console.WriteLine("XmlConvert.ToString(TimeSpan.FromMilliseconds(" +
+milliseconds + ")) returns '" +
+XmlConvert.ToString(TimeSpan.FromMilliseconds(milliseconds)) + "'");
+
+            timespan = "PT0.100S";
+            Console.WriteLine("XmlConvert.ToTimeSpan('" + timespan + "')
+returns " + XmlConvert.ToTimeSpan(timespan).Milliseconds + " milliseconds");
+            timespan = "PT0.1S";
+            Console.WriteLine("XmlConvert.ToTimeSpan('" + timespan + "')
+returns " + XmlConvert.ToTimeSpan(timespan).Milliseconds + " milliseconds");
+
+            timespan = "PT0.010S";
+            Console.WriteLine("XmlConvert.ToTimeSpan('" + timespan + "')
+returns " + XmlConvert.ToTimeSpan(timespan).Milliseconds + " milliseconds");
+            timespan = "PT0.01S";
+            Console.WriteLine("XmlConvert.ToTimeSpan('" + timespan + "')
+returns " + XmlConvert.ToTimeSpan(timespan).Milliseconds + " milliseconds");
+
+            timespan = "PT0.001S";
+            Console.WriteLine("XmlConvert.ToTimeSpan('" + timespan + "')
+returns " + XmlConvert.ToTimeSpan(timespan).Milliseconds + " milliseconds");
+
+
+
+            System.Console.WriteLine("Done");
+        }
+    }
+}
+
+Running on .NET produces 
+
+XmlConvert.ToString(TimeSpan.FromMilliseconds(100)) returns 'PT0.1S'
+XmlConvert.ToString(TimeSpan.FromMilliseconds(10)) returns 'PT0.01S'
+XmlConvert.ToString(TimeSpan.FromMilliseconds(1)) returns 'PT0.001S'
+XmlConvert.ToTimeSpan('PT0.100S') returns 100 milliseconds
+XmlConvert.ToTimeSpan('PT0.1S') returns 100 milliseconds
+XmlConvert.ToTimeSpan('PT0.010S') returns 10 milliseconds
+XmlConvert.ToTimeSpan('PT0.01S') returns 10 milliseconds
+XmlConvert.ToTimeSpan('PT0.001S') returns 1 milliseconds
+
+This code will hang when run on Mono.  
+
+Actual Results:
+hangs.
+
+Expected Results:
+same as MS
+
+How often does this happen? 
+Aways
+
+Additional Information:
+
+Proposed patch:
+
+Index: mcs/class/System.XML/System.Xml/XmlConvert.cs
+===================================================================
+--- mcs/class/System.XML/System.Xml/XmlConvert.cs       (revision 51141)
++++ mcs/class/System.XML/System.Xml/XmlConvert.cs       (working copy)
+@@ -439,8 +439,14 @@
+                                        builder.Append
+(value.Minutes).Append ('M');
+                                if (value.Seconds > 0 || value.Milliseconds
+> 0) {
+                                        builder.Append (value.Seconds);
+-                                       if (value.Milliseconds > 0)
+-                                               builder.Append
+('.').AppendFormat ("{0:000}", value.Milliseconds);
++                                        if (value.Milliseconds > 0)
++                                          builder.Append('.');
++                                        if (value.Milliseconds % 100 == 0)
++                                          builder.AppendFormat("{0:0}",
+value.Milliseconds / 100);
++                                        else if (value.Milliseconds % 10 == 0)
++                                          builder.AppendFormat("{0:00}",
+value.Milliseconds / 10);
++                                        else 
++                                          builder.AppendFormat("{0:000}",
+value.Milliseconds);
+                                        builder.Append ('S');
+                                }
+                        }
+@@ -563,11 +569,10 @@
+                                        parsedDigits = i - start;
+                                int value = int.Parse (s.Substring (start,
+i - start), CultureInfo.InvariantCulture);
+                                if (parseStep == 7) {
+-                                       // adjust to 3 digits so that it
+makes sense as millisecond digits
+-                                       while (parsedDigits > 3)
+-                                               value /= 10;
+-                                       while (parsedDigits < 3)
+-                                               value *= 10;
++                                if (i - start == 1) 
++                                  value *= 100;
++                                else if (i - start == 2) 
++                                  value *= 10;
+                                }
+                                switch (s [i]) {
+                                case 'Y':
+[awaddell at AWLNX src]$


More information about the mono-bugs mailing list