After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 777139 - Wrong calculation of max xs:duration
Wrong calculation of max xs:duration
Status: RESOLVED OBSOLETE
Product: libxml2
Classification: Platform
Component: xmlschema
git master
Other All
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2017-01-11 14:47 UTC by amarant
Modified: 2021-07-05 13:24 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description amarant 2017-01-11 14:47:19 UTC
Hi,
there is erroneous calculations of the inclusion of a duration in a max duration type, for example with a type for a duration to 10 years, 1461 days is ok, but not 1462.

with the schema :

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:simpleType name="Duration10YearsType">
        <xs:restriction base="xs:duration">
            <xs:maxInclusive value="P10Y"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:element name="durationTest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="d" type="Duration10YearsType"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

This xml doesn't validate :
<?xml version="1.0" encoding="UTF-8"?>
<durationTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="duration.xsd">
    <d>P1462D</d>
</durationTest>

And this one does :
<?xml version="1.0" encoding="UTF-8"?>
<durationTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="duration.xsd">
    <d>P1461D</d>
</durationTest>

1461 days is 4*365+1, 1462 days is 4*365+2, still a long way from more than 10 years.

I suspect the code in the function xmlSchemaCompareDurations of the file xmlschemastypes.c to be wrong, mostly on the lines :
maxday = 366 * ((myear + 3) / 4) + 365 * ((myear - 1) % 4);
it doesn't seems to handle more than 5 years with the modulo.

Thanks.
Comment 1 Nick Wellnhofer 2019-08-25 12:58:19 UTC
This was partially fixed here: https://gitlab.gnome.org/GNOME/libxml2/commit/e3f1c7f751192d8f271a86e314ab12556293786b
Comment 2 GNOME Infrastructure Team 2021-07-05 13:24:19 UTC
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org.
As part of that, we are mass-closing older open tickets in bugzilla.gnome.org
which have not seen updates for a longer time (resources are unfortunately
quite limited so not every ticket can get handled).

If you can still reproduce the situation described in this ticket in a recent
and supported software version, then please follow
  https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines
and create a new ticket at
  https://gitlab.gnome.org/GNOME/libxml2/-/issues/

Thank you for your understanding and your help.