Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
d7347b79 by wurstsalat at 2025-05-29T12:03:51+02:00
fix: File handling: Catch file access errors (file transfer, avatars)
Fixes #12310
- - - - -
3 changed files:
- gajim/common/util/uri.py
- gajim/gtk/avatar_selector.py
- gajim/gtk/file_transfer_selector.py
Changes:
=====================================
gajim/common/util/uri.py
=====================================
@@ -263,6 +263,29 @@ def get_file_path_from_dnd_dropped_uri(text: str) -> Path
| None:
return filesystem_path_from_uri(uri)
+def get_file_path_from_uri(uri: str) -> Path | None:
+ """Prepare URI by:
+ - removing invalid characters
+ - parsing and checking the URI for validity
+ - checking if the path is a file
+ - checking if the file is accessible (path.is_file() calls Path.stat())
+ """
+ path = get_file_path_from_dnd_dropped_uri(uri)
+ if path is None:
+ return None
+
+ try:
+ is_file = path.is_file()
+ except OSError:
+ log.exception("Could not access file: %s", path)
+ return None
+
+ if not is_file:
+ return None
+
+ return path
+
+
def make_path_from_jid(base_path: Path, jid: JID) -> Path:
assert jid.domain is not None
domain = jid.domain[:50]
=====================================
gajim/gtk/avatar_selector.py
=====================================
@@ -25,7 +25,7 @@
from gajim.common.const import AvatarSize
from gajim.common.i18n import _
from gajim.common.util.image import scale_with_ratio
-from gajim.common.util.uri import get_file_path_from_dnd_dropped_uri
+from gajim.common.util.uri import get_file_path_from_uri
from gajim.gtk.dialogs import SimpleDialog
from gajim.gtk.filechoosers import AvatarFileChooserButton
@@ -127,8 +127,8 @@ def _on_file_drop(
if not files:
return False
- path = get_file_path_from_dnd_dropped_uri(files[0].get_uri())
- if not path or not path.is_file():
+ path = get_file_path_from_uri(files[0].get_uri())
+ if path is None:
return False
self.prepare_crop_area(str(path))
=====================================
gajim/gtk/file_transfer_selector.py
=====================================
@@ -25,7 +25,7 @@
from gajim.common.preview import PREVIEWABLE_MIME_TYPES
from gajim.common.util.preview import get_icon_for_mime_type
from gajim.common.util.preview import guess_mime_type
-from gajim.common.util.uri import get_file_path_from_dnd_dropped_uri
+from gajim.common.util.uri import get_file_path_from_uri
from gajim.gtk.builder import get_builder
from gajim.gtk.filechoosers import FileChooserButton
@@ -164,11 +164,9 @@ def get_catalog(self) -> list[tuple[Path, str, JID]]:
def add_files(self, uris: list[str]) -> None:
for uri in uris:
- path = get_file_path_from_dnd_dropped_uri(uri)
- if path is None or not path.is_file():
- self._add_warning_message(
- "Could not add %s" % (str(path) if path else uri)
- )
+ path = get_file_path_from_uri(uri)
+ if path is None:
+ self._add_warning_message("Could not add %s" % uri)
continue
size_warning = bool(
@@ -209,10 +207,6 @@ def _on_file_drop(
if not files:
return False
- path = get_file_path_from_dnd_dropped_uri(files[0].get_uri())
- if not path or not path.is_file():
- return False
-
self.add_files([file.get_uri() for file in files])
return True
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/d7347b7945e41154fb2566b9621eaf270b4d3351
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/d7347b7945e41154fb2566b9621eaf270b4d3351
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]