diff --git a/SOURCES/0004-text-input-crash.patch b/SOURCES/0004-text-input-crash.patch
new file mode 100644
index 0000000..91bacf1
--- /dev/null
+++ b/SOURCES/0004-text-input-crash.patch
@@ -0,0 +1,12 @@
+--- src/libnrtype/Layout-TNG-OutIter.cpp~       2018-03-11 16:38:09.000000000 -0400
++++ src/libnrtype/Layout-TNG-OutIter.cpp        2018-06-16 13:17:03.129605681 -0400
+@@ -182,6 +182,8 @@
+     if (_input_stream[source_index]->Type() != TEXT_SOURCE)
+         return iterator(this, char_index);
+
++    if (char_index >= _characters.size())
++        return end();
+     return iterator(this, char_index);
+     /* This code was never used, the text_iterator argument was "NULL" in all calling code
+     InputStreamTextSource const *text_source = static_cast<InputStreamTextSource const *>(_input_stream[source_index]);
+
diff --git a/SPECS/inkscape.spec b/SPECS/inkscape.spec
index 548e4c3..ca1db2c 100644
--- a/SPECS/inkscape.spec
+++ b/SPECS/inkscape.spec
@@ -2,7 +2,7 @@
 
 Name:           inkscape
 Version:        0.92.3
-Release:        13%{?dist}
+Release:        16%{?dist}
 Summary:        Vector-based drawing program using SVG
 
 License:        GPLv2+ and CC-BY
@@ -22,6 +22,7 @@ Patch1:   0003-use-python2.patch
 Patch2:   inkscape-poppler-0.64.0.patch
 Patch3:   inkscape-poppler-0.65.0.patch
 Patch4:   inkscape-poppler-20.11.0.patch
+Patch5:        0004-text-input-crash.patch
 
 BuildRequires:  aspell-devel aspell-en
 BuildRequires:  atk-devel
@@ -83,15 +84,17 @@ Requires:       transfig
 Requires:       gimp
 %endif
 
-%if !0%{?flatpak}
 Requires:       python2-lxml
 Requires:       python2-numpy
 Suggests:       uniconvertor
 Requires:	python2-scour
-%endif
 
 # For ClipArt functionality
+%if 0%{?flatpak}
+Requires:       gvfs-client
+%else
 Requires:       gvfs
+%endif
 
 Provides: bundled(libcroco) = 0.6
 
@@ -139,6 +142,7 @@ rpmbuild --showrc
 %patch2 -p1 -b .poppler-0.64.0
 %patch3 -p1 -b .poppler-0.65.0
 %patch4 -p1 -b .poppler-20.11.0
+%patch5 -p0 -b .text-input-crash
 
 # https://bugs.launchpad.net/inkscape/+bug/314381
 # A couple of files have executable bits set,
@@ -206,8 +210,10 @@ echo "==============================="
         -DCMAKE_C_FLAGS_RELEASE:STRING="$CFLAGS -DNDEBUG -fno-strict-aliasing -I$BUNDLED_PREFIX/$INSTALL_PREFIX/include/ImageMagick-6" \
         -DCMAKE_CXX_FLAGS_RELEASE:STRING="$CXXFLAGS -DNDEBUG -I$BUNDLED_PREFIX/$INSTALL_PREFIX/include/ImageMagick-6" \
         -DCMAKE_Fortran_FLAGS_RELEASE:STRING="$FCFLAGS -DNDEBUG" \
+%if 0%{?bundle_im}
         -DCMAKE_SHARED_LINKER_FLAGS:STRING="$LDFLAGS -L$BUNDLED_PREFIX%{_libdir} -Wl,-rpath,/$INSTALL_PREFIX/lib/inkscape" \
         -DCMAKE_EXE_LINKER_FLAGS:STRING="$LDFLAGS -L$BUNDLED_PREFIX%{_libdir} -Wl,-rpath,/$INSTALL_PREFIX/lib/inkscape" \
+%endif
         -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
         -DCMAKE_INSTALL_PREFIX:PATH=/$INSTALL_PREFIX \
         -DINCLUDE_INSTALL_DIR:PATH=/$INSTALL_PREFIX/include \
@@ -262,6 +268,15 @@ rm -rf $BUNDLED_PREFIX%{_prefix}/%{_lib}/perl5
 cp -r $BUNDLED_PREFIX%{_prefix}/%{_lib}/* $RPM_BUILD_ROOT%{_prefix}/%{_lib}
 %endif
 
+%if 0%{?flatpak}
+# Remove /usr/bin/env/python2? in a way that works for both /usr/bin/python2
+# and /app/bin/python2 (brp-mangle-shebangs doesn't)
+grep -E -rl '^#!\s*/usr/bin/env\s+python' --include=\*.py "%{buildroot}" |
+    while read file; do
+        sed -r '1s,^#!\s*/usr/bin/env\s+python(2?)(\s|$),#!%{__python2}\2,' -i "$file"
+    done
+%endif
+
 #%check
 # XXX: Tests fail, ignore it for now
 #make -k check || :
@@ -320,6 +335,15 @@ cp -r $BUNDLED_PREFIX%{_prefix}/%{_lib}/* $RPM_BUILD_ROOT%{_prefix}/%{_lib}
 
 
 %changelog
+* Mon Nov 08 2021 Jan Horak <jhorak@redhat.com> - 0.92.3-16
+- Fixing crashes on text input, rhbz#1997106
+
+* Thu May 13 2021 Jan Horak <jhorak@redhat.com> - 0.92.3-15
+- Added python dependency for the flatpak too
+
+* Mon May 10 2021 Jan Horak <jhorak@redhat.com> - 0.92.3-14
+- Use rpath only for the bundled im
+
 * Wed Jul 10 2019 Jan Horak <jhorak@redhat.com> - 0.92.3-13
 - Rebuild due to newer poppler