[xml] format-number fails on large numbers (> 4294967295)



VERSIONS: libxml2-2.4.3
          libxslt-1.0.3


PROBLEM:
   The function format-number fails on large numbers specifically greater
than (INT_MAX * 2).  It fails due to string number conversion in function
xmlXPathStringEvalNumber where it uses an unsigned int as buffer to convert
to a double.  When the string number exceeds (INT_MAX * 2), the buffer
overflows and the incorrect value is then returned casted to a double
number.  
   In function xmlXPathStringEvalNumber, it was noted that the tmp buffer is
used to get around gcc compiler bug.  Using gcc 2.96 and Linux 7.2SBE kernel
2.4.3-6smp, I tested the same function that does not use the tmp buffer
(i.e.. store the value directly to the variable ret) and it works fine with
numbers greater than 1.0e+24 as input.


SAMPLE DATA TO REPRODUCE:
-------------------------------------------- sample.xsl ---
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:fo="http://www.w3.org/1999/XSL/Format";>
<xsl:strip-space elements="*"/>
<xsl:output method="xml"/>
        <xsl:template match="hipda/TestData">
Formatted value is: <xsl:value-of select="format-number((FreeSpace div
(1024*1024*1024)),'#,##0.00 GB')" />
         Expecting: <xsl:value-of select="ExpectedValue" />
        </xsl:template>
</xsl:stylesheet>
-------------------------------------------- sample.xml ---
<?xml-stylesheet type="text/xsl" version="1.0" encoding="UTF-8"?>
<hipda>
  <TestData><FreeSpace>1</FreeSpace><ExpectedValue>0.00
GB</ExpectedValue></TestData>
  <TestData><FreeSpace>-2147483648</FreeSpace><ExpectedValue>-2.00
GB</ExpectedValue></TestData>
  <TestData><FreeSpace>4294967295</FreeSpace><ExpectedValue>4.00
GB</ExpectedValue></TestData>
  <TestData><FreeSpace>4294967296</FreeSpace><ExpectedValue>4.00
GB</ExpectedValue></TestData>
  <TestData><FreeSpace>4789895168</FreeSpace><ExpectedValue>4.46
GB</ExpectedValue></TestData>
 
<TestData><FreeSpace>999999999999999999999999</FreeSpace><ExpectedValue>931,
322,574,615,478.52 GB</ExpectedValue></TestData>
</hipda>
-------------------------------------------- output ---
Formatted value is: 0.00 GB
         Expecting: 0.00 GB                        ok
Formatted value is: -2.00 GB
         Expecting: -2.00 GB                       ok
Formatted value is: 4.00 GB
         Expecting: 4.00 GB                        ok
Formatted value is: 0.00 GB
         Expecting: 4.00 GB                        FAIL
Formatted value is: 0.46 GB
         Expecting: 4.46 GB                        FAIL
Formatted value is: 2.52 GB
         Expecting: 931,322,574,615,478.52 GB      FAIL
--------------------------------------------



_______________________________
Chris Poblete
Dell © Enterprise Servers Group






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]