[Libreoffice-commits] core.git: sw/source

Michael Stahl mstahl at redhat.com
Mon Nov 6 19:30:28 UTC 2017


 sw/source/core/doc/tblafmt.cxx   |   15 ++++++++++-----
 sw/source/core/layout/atrfrm.cxx |   32 ++++++++++++++++++++++----------
 2 files changed, 32 insertions(+), 15 deletions(-)

New commits:
commit cc88a2bcfddd19e90a44f1b0bc1c1ef31a86768f
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Nov 3 13:20:14 2017 +0100

    sw: read both platform dependent binary table autoformats
    
    The WriterSpecificAutoFormatBlock class actually writes a length
    into the file that covers the offending SwFormatVertOrient item.
    
    Put in a gross hack to read either 32-bit or 64-bit in
    SwFormatVertOrient::Store depending on that length.
    
    The length also covers another item, so we'll just hope nobody ever
    changes this stuff ever again!
    
    Change-Id: Idf2f05cc00c098571508adb849f60940966c3328
    Reviewed-on: https://gerrit.libreoffice.org/44254
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>

diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx
index 4c66817309de..8235c52f77dd 100644
--- a/sw/source/core/doc/tblafmt.cxx
+++ b/sw/source/core/doc/tblafmt.cxx
@@ -149,13 +149,13 @@ namespace
     };
 
     /// Checks whether a writer-specific block exists (i.e. size is not zero)
-    bool WriterSpecificBlockExists(SvStream &stream)
+    sal_Int64 WriterSpecificBlockExists(SvStream &stream)
     {
         sal_uInt64 endOfSwBlock = 0;
         stream.ReadUInt64( endOfSwBlock );
 
         // end-of-block pointing to itself indicates a zero-size block.
-        return endOfSwBlock != stream.Tell();
+        return endOfSwBlock - stream.Tell();
     }
 }
 
@@ -452,10 +452,15 @@ bool SwBoxAutoFormat::Load( SvStream& rStream, const SwAfVersions& rVersions, sa
     SetAdjust( *static_cast<SvxAdjustItem*>(pNew) );
     delete pNew;
 
-    if (nVer >= AUTOFORMAT_DATA_ID_31005 && WriterSpecificBlockExists(rStream))
+    if (nVer >= AUTOFORMAT_DATA_ID_31005)
     {
-        READ(m_aTextOrientation, SvxFrameDirectionItem, rVersions.m_nTextOrientationVersion);
-        READ(m_aVerticalAlignment, SwFormatVertOrient, rVersions.m_nVerticalAlignmentVersion);
+        sal_Int64 const nSize(WriterSpecificBlockExists(rStream));
+        if (0 < nSize && nSize < std::numeric_limits<sal_uInt16>::max())
+        {
+            READ(m_aTextOrientation, SvxFrameDirectionItem, rVersions.m_nTextOrientationVersion);
+            // HORRIBLE HACK to read both 32-bit and 64-bit "long": abuse nSize
+            READ(m_aVerticalAlignment, SwFormatVertOrient, /*rVersions.m_nVerticalAlignmentVersion*/ nSize);
+        }
     }
 
     READ( m_aHorJustify,  SvxHorJustifyItem , rVersions.nHorJustifyVersion)
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index d03983a46fd4..76bc2b14a944 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -1265,20 +1265,32 @@ SvStream& SwFormatVertOrient::Store(SvStream &rStream, sal_uInt16 /*version*/) c
     return rStream;
 }
 
-SfxPoolItem* SwFormatVertOrient::Create(SvStream &rStream, sal_uInt16 /*itemVersion*/) const
+SfxPoolItem* SwFormatVertOrient::Create(SvStream &rStream, sal_uInt16 nVersionAbusedAsSize) const
 {
     SwTwips yPos(0);
     sal_Int16 orient(0);
     sal_Int16 relation(0);
-    // compatibility hack for Table Auto Format: SwTwips is "long" :(
-    // (this means that the file format is platform dependent)
-#if SAL_TYPES_SIZEOFLONG == 8
-    rStream.ReadInt64(yPos);
-#else
-    sal_Int32 n;
-    rStream.ReadInt32(n);
-    yPos = n;
-#endif
+    switch (nVersionAbusedAsSize)
+    {
+        // compatibility hack for Table Auto Format: SwTwips is "long" :(
+        // (this means that the file format is platform dependent)
+    case 14:
+        {
+            sal_Int64 n(0);
+            rStream.ReadInt64(n);
+            yPos = n;
+        }
+        break;
+    case 10:
+        {
+            sal_Int32 n(0);
+            rStream.ReadInt32(n);
+            yPos = n;
+        }
+        break;
+    default:
+        SAL_WARN("sw.core", "SwFormatVertOrient::Create: unknown size");
+    }
     rStream.ReadInt16( orient ).ReadInt16( relation );
 
     return new SwFormatVertOrient(yPos, orient, relation);


More information about the Libreoffice-commits mailing list