vcl/ios/iOSTransferable.cxx  |   10 ++++++++++
 vcl/source/window/dialog.cxx |   13 +++++++++++++
 2 files changed, 23 insertions(+)

New commits:
commit 178fd44a0311c49c8202a162f70c9976afbb1be1
Author:     Patrick Luby <patrick.l...@collabora.com>
AuthorDate: Fri Mar 10 12:11:25 2023 -0500
Commit:     Patrick Luby <plub...@neooffice.org>
CommitDate: Thu Mar 16 16:28:57 2023 +0000

    Handle pasting disallowed clipboard contents on iOS
    
    When another app owns the current clipboard contents, pasting
    will display a "allow or disallow" dialog. If the disallow
    option is selected, the data from the UIPasteboard will be
    garbage and GetLOKNotifier() will return a nullptr. Since calling
    SetLOKNotifier() with a nullptr aborts in an assert(), fix the
    crash by failing gracefully.
    
    Also, throw an exception if the -[UIPasteboard dataForPasteboardType:]
    returns nil. By throwing an exception,  the "allow or disallow"
    dialog will display again the next time the user tries to paste.
    
    Change-Id: I05d689b679a7643a8478e3ce0f416205fdf8ec23
    Reference-to: https://github.com/CollaboraOnline/online/issues/5908
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148655
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>
    (cherry picked from commit 1dd68786a927a23e5465589025abd90b8c9f4e7b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148626
    Tested-by: Jenkins
    Reviewed-by: Patrick Luby <plub...@neooffice.org>

diff --git a/vcl/ios/iOSTransferable.cxx b/vcl/ios/iOSTransferable.cxx
index ece771e7f60b..bfbc8a9afa82 100644
--- a/vcl/ios/iOSTransferable.cxx
+++ b/vcl/ios/iOSTransferable.cxx
@@ -109,6 +109,16 @@ Any SAL_CALL iOSTransferable::getTransferData(const 
DataFlavor& aFlavor)
     DataProviderPtr_t dp;
 
     NSData* sysData = [[UIPasteboard generalPasteboard] 
dataForPasteboardType:sysFormat];
+    if (!sysData)
+    {
+        // Related: gh#5908 throw an exception if the data flavor is nil
+        // If nil is returned, it can mean that the user has selected the
+        // "disallow" option and so we can't access the current clipboard
+        // contents. Also, by throwing an exception, the "allow or disallow"
+        // dialog will display again the next time the user tries to paste.
+        throw UnsupportedFlavorException("Data flavor is nil", 
static_cast<XTransferable*>(this));
+    }
+
     dp = DataFlavorMapper::getDataProvider(sysFormat, sysData);
 
     if (dp.get() == nullptr)
diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index b8d81a4b8130..bbf6b4a0078c 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -926,7 +926,20 @@ bool Dialog::ImplStartExecute()
     if (bModal)
     {
         if (bKitActive && !GetLOKNotifier())
+        {
+#ifdef IOS
+            // gh#5908 handle pasting disallowed clipboard contents on iOS
+            // When another app owns the current clipboard contents, pasting
+            // will display a "allow or disallow" dialog. If the disallow
+            // option is selected, the data from the UIPasteboard will be
+            // garbage and we will find ourselves here. Since calling
+            // SetLOKNotifier() with a nullptr aborts in an assert(), fix
+            // the crash by failing gracefully.
+            return false;
+#else
             
SetLOKNotifier(mpDialogImpl->m_aInstallLOKNotifierHdl.Call(nullptr));
+#endif
+        }
 
         switch ( Application::GetDialogCancelMode() )
         {

Reply via email to