GNOME Bugzilla – Bug 777139
Wrong calculation of max xs:duration
Last modified: 2021-07-05 13:24: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.
This was partially fixed here: https://gitlab.gnome.org/GNOME/libxml2/commit/e3f1c7f751192d8f271a86e314ab12556293786b
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.