sw/source/filter/ww8/docxattributeoutput.cxx |   11 +++++++----
 sw/source/filter/ww8/docxsdrexport.cxx       |   10 +++++++---
 2 files changed, 14 insertions(+), 7 deletions(-)

New commits:
commit 0c872e6973f1ed0a2386e3534f2cb69db6a693b5
Author:     Justin Luth <[email protected]>
AuthorDate: Fri Mar 6 09:48:11 2026 -0500
Commit:     Justin Luth <[email protected]>
CommitDate: Mon Mar 9 13:41:57 2026 +0100

    tdf#169487: docx export: invalid values in a:Ext
    
    This patch is similar to a prior one,
    just applied in a different section of code.
    
    MS Office is not accepting values greater than 2147483647
    for 'x' and 'y' attributes inside a:off,
    or 'cx' and 'cy' attributes inside 'a:chExt'
    
    MSO was reporting those documents as corrupt. Specifically:
    -ooo112797-1.odt
    -tdf128906-1.odt
    -tdf128906-2.odt
    -tdf128828-1.odt
    
    Change-Id: I802c7b6809cd4398bed92b130fef38ef4e1ab2ea
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201160
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <[email protected]>

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index dc5292d71cec..ba3fd8d76cb2 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -5749,10 +5749,13 @@ void DocxAttributeOutput::FlyFrameGraphic( const 
SwGrfNode* pGrfNode, const Size
     m_pSerializer->startElementNS(XML_a, XML_xfrm, xFrameAttributes);
 
     m_pSerializer->singleElementNS(XML_a, XML_off, XML_x, "0", XML_y, "0");
-    // clamp to >=0, negative values are not valid here
-    OString aWidth( OString::number( std::max(sal_Int64(0), TwipsToEMU( 
aSize.Width() )) ) );
-    OString aHeight( OString::number( std::max(sal_Int64(0), TwipsToEMU( 
aSize.Height() )) ) );
-    m_pSerializer->singleElementNS(XML_a, XML_ext, XML_cx, aWidth, XML_cy, 
aHeight);
+
+    // MS Word reports the document as corrupt if not positive, Int32 value
+    const sal_Int32 nWidth = std::clamp<sal_Int64>(TwipsToEMU(aSize.Width()), 
0, SAL_MAX_INT32);
+    const sal_Int32 nHeight = 
std::clamp<sal_Int64>(TwipsToEMU(aSize.Height()), 0, SAL_MAX_INT32);
+    m_pSerializer->singleElementNS(
+        XML_a, XML_ext, XML_cx, OString::number(nWidth), XML_cy, 
OString::number(nHeight));
+
     m_pSerializer->endElementNS( XML_a, XML_xfrm );
     m_pSerializer->startElementNS(XML_a, XML_prstGeom, XML_prst, "rect");
     m_pSerializer->singleElementNS(XML_a, XML_avLst);
diff --git a/sw/source/filter/ww8/docxsdrexport.cxx 
b/sw/source/filter/ww8/docxsdrexport.cxx
index 13fe56ad7f24..29600ca26ac3 100644
--- a/sw/source/filter/ww8/docxsdrexport.cxx
+++ b/sw/source/filter/ww8/docxsdrexport.cxx
@@ -1885,9 +1885,13 @@ void DocxSdrExport::writeDMLTextFrame(ww8::Frame const* 
pParentFrame, bool bText
             pFS->startElementNS(XML_a, XML_xfrm);
         }
         pFS->singleElementNS(XML_a, XML_off, XML_x, "0", XML_y, "0");
-        OString aWidth(OString::number(TwipsToEMU(aSize.Width())));
-        OString aHeight(OString::number(TwipsToEMU(aSize.Height())));
-        pFS->singleElementNS(XML_a, XML_ext, XML_cx, aWidth, XML_cy, aHeight);
+
+        // MS Word reports the document as corrupt if not positive, Int32 value
+        const sal_Int32 nW = std::clamp<sal_Int64>(TwipsToEMU(aSize.Width()), 
0, SAL_MAX_INT32);
+        const sal_Int32 nH = std::clamp<sal_Int64>(TwipsToEMU(aSize.Height()), 
0, SAL_MAX_INT32);
+        pFS->singleElementNS(XML_a, XML_ext, XML_cx, OString::number(nW), 
XML_cy,
+                             OString::number(nH));
+
         pFS->endElementNS(XML_a, XML_xfrm);
         OUString shapeType = u"rect"_ustr;
         if (xPropSetInfo.is() && 
xPropSetInfo->hasPropertyByName(u"FrameInteropGrabBag"_ustr))

Reply via email to