oox/source/core/xmlfilterbase.cxx | 18 +++++------------- sc/qa/unit/data/xlsx/tdf169072_illegalDates.xlsx |binary sc/qa/unit/subsequent_export_test2.cxx | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 13 deletions(-)
New commits: commit 877eedc73c0349b39b07e19e01fa2dca422448c8 Author: Justin Luth <[email protected]> AuthorDate: Fri Dec 5 18:17:23 2025 -0500 Commit: Adolfo Jayme Barrientos <[email protected]> CommitDate: Fri Dec 12 05:22:04 2025 +0100 tdf#169072 ms export: valid date years are 1601 - 9999 #2 The dates in core.xml must fall in the range of 1601 - 9999. This applies to all MS files, not just DOCX. Plus, the entire concept of ISOIEC_29500_2008 was wrongly implemented... make CppunitTest_sc_subsequent_export_test2 \ CPPUNIT_TEST_NAME=testTdf169072_illegalDates Change-Id: I06ddc69ff79f1c8d744d97782617f8be257021a5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195139 Reviewed-by: Justin Luth <[email protected]> Tested-by: Jenkins (cherry picked from commit ef5846a1ea802f580508984baa6dc76d3d9d617f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195160 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195463 Reviewed-by: Adolfo Jayme Barrientos <[email protected]> diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx index 59ed57bda82e..5426d2d57010 100644 --- a/oox/source/core/xmlfilterbase.cxx +++ b/oox/source/core/xmlfilterbase.cxx @@ -567,21 +567,13 @@ OUString XmlFilterBase::addRelation( const Reference< XOutputStream >& rOutputSt return OUString(); } -static bool lcl_isValidDate(const util::DateTime& rTime, XmlFilterBase& rSelf) +static bool lcl_isValidDate(const util::DateTime& rTime) { if (rTime.Year == 0) return false; // MS Office reports document as corrupt if core.xml contains any Year <= 1600 or > 9999 - // for the "package" URI (ECMA_376_1ST_EDITION or docx). - if (rTime.Year > 1600 && rTime.Year < 10000) - return true; - - const bool bDocx = dynamic_cast<text::XTextDocument*>(rSelf.getModel().get()); - if (bDocx || rSelf.getVersion() == oox::core::ECMA_376_1ST_EDITION) - return false; - - return true; + return rTime.Year > 1600 && rTime.Year < 10000; } static void @@ -725,7 +717,7 @@ writeCoreProperties( XmlFilterBase& rSelf, const Reference< XDocumentProperties if (!bRemoveUserInfo) { const util::DateTime aCreateDate = xProperties->getCreationDate(); - if (lcl_isValidDate(aCreateDate, rSelf)) + if (lcl_isValidDate(aCreateDate)) writeElement(pCoreProps, FSNS(XML_dcterms, XML_created), aCreateDate); writeElement(pCoreProps, FSNS(XML_dc, XML_creator), xProperties->getAuthor()); } @@ -745,11 +737,11 @@ writeCoreProperties( XmlFilterBase& rSelf, const Reference< XDocumentProperties { writeElement(pCoreProps, FSNS(XML_cp, XML_lastModifiedBy), xProperties->getModifiedBy()); const util::DateTime aPrintDate = xProperties->getPrintDate(); - if (lcl_isValidDate(aPrintDate, rSelf)) + if (lcl_isValidDate(aPrintDate)) writeElement(pCoreProps, FSNS(XML_cp, XML_lastPrinted), aPrintDate); const util::DateTime aModifyDate = xProperties->getModificationDate(); - if (lcl_isValidDate(aModifyDate, rSelf)) + if (lcl_isValidDate(aModifyDate)) writeElement(pCoreProps, FSNS(XML_dcterms, XML_modified), aModifyDate); } if (!bRemovePersonalInfo) diff --git a/sc/qa/unit/data/xlsx/tdf169072_illegalDates.xlsx b/sc/qa/unit/data/xlsx/tdf169072_illegalDates.xlsx new file mode 100644 index 000000000000..80802593c131 Binary files /dev/null and b/sc/qa/unit/data/xlsx/tdf169072_illegalDates.xlsx differ diff --git a/sc/qa/unit/subsequent_export_test2.cxx b/sc/qa/unit/subsequent_export_test2.cxx index 5732eee455c9..08c3530cabf9 100644 --- a/sc/qa/unit/subsequent_export_test2.cxx +++ b/sc/qa/unit/subsequent_export_test2.cxx @@ -957,6 +957,20 @@ CPPUNIT_TEST_FIXTURE(ScExportTest2, testXltxExport) u"application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml"); } +CPPUNIT_TEST_FIXTURE(ScExportTest2, testTdf169072_illegalDates) +{ + // Given a document that MS Word reports as corrupt + createScDoc("xlsx/tdf169072_illegalDates.xlsx"); + save(TestFilter::XLSX); + + // Date Years MUST be greater than 1600 and less than 10,000 + // so by dropping invalid entries, we have a document that MS Excel can now cleanly open + xmlDocUniquePtr pXmlCore = parseExport(u"docProps/core.xml"_ustr); + assertXPathContent(pXmlCore, "/cp:coreProperties/dcterms:created", u"9999-10-10T13:07:54Z"); + assertXPathContent(pXmlCore, "/cp:coreProperties/dcterms:modified", u"1601-01-01T13:09:08Z"); + assertXPath(pXmlCore, "/cp:coreProperties/cp:lastPrinted", 0); // was 1600-12-31T00:00:52Z +} + CPPUNIT_TEST_FIXTURE(ScExportTest2, testTdf165180_date1904) { // given a hand-modified document (which added dateCompatibility="0")
