vcl/qt5/QtTransferable.cxx |    3 +++
 1 file changed, 3 insertions(+)

New commits:
commit 8d98f231fa2d3f4386a842d0f45a9ceeea4ab8e1
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Feb 15 08:52:25 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Feb 16 09:09:28 2024 +0100

    tdf#156562 qt: Don't crash on null clipboard content
    
    Since
    
        commit 1db5b87fe69c2375f1d66974dafcd563303c76db
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Tue Feb 13 13:23:17 2024 +0100
    
            tdf#156562 qt: Sync with system clipboard content if necessary
    
    , mime data are updated from the system clipboard when there's
    a mismatch.
    
    Quoting Stephan Bergmann's [1]:
    
    > PS2, Line 174:         setMimeData(pCurrentClipboardData);
    > At least for my Qt6-based Emscripten build, `pCurrentClipboardData`
    > can be null here, so setting `QtTransferable::m_pMimeData` to null here,
    > and a later call to `QtTransferable::getTransferDataFlavors` will
    > call `m_pMimeData->formats()` and crash.
    
    Add a corresponding null check.
    
    From what I can see, other methods shouldn't need an explicit check,
    as they use the result of `QtTransferable::getTransferData`
    (e.g. `QtTransferable::getTransferData` returns early if
    `QtTransferable::isDataFlavorSupported` returns false, which in
    turn calls `QtTransferable::getTransferData` that now has this
    null check).
    
    [1] https://gerrit.libreoffice.org/c/core/+/163304/comment/8872708d_1abdef81
    
    Change-Id: Ibec756c2b073b1e19a3b4761e57c35576b44adc3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163423
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtTransferable.cxx b/vcl/qt5/QtTransferable.cxx
index 41c2c58392ef..18c2583e2e63 100644
--- a/vcl/qt5/QtTransferable.cxx
+++ b/vcl/qt5/QtTransferable.cxx
@@ -50,6 +50,9 @@ QtTransferable::QtTransferable(const QMimeData* pMimeData)
 
 css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL 
QtTransferable::getTransferDataFlavors()
 {
+    if (!m_pMimeData)
+        return css::uno::Sequence<css::datatransfer::DataFlavor>();
+
     QStringList aFormatList(m_pMimeData->formats());
     // we might add the UTF-16 mime text variant later
     const int nMimeTypeSeqSize = aFormatList.size() + 1;

Reply via email to