After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 688798 - Broken handling of non-local files
Broken handling of non-local files
Status: RESOLVED FIXED
Product: gnome-boxes
Classification: Applications
Component: general
3.9.x
Other Linux
: Normal normal
: --
Assigned To: GNOME Boxes maintainer(s)
GNOME Boxes maintainer(s)
Depends on:
Blocks: 696727
 
 
Reported: 2012-11-21 11:07 UTC by Bastien Nocera
Modified: 2016-03-31 13:56 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
media-manager: Work around vala bug#706517 (1.42 KB, patch)
2013-08-21 20:43 UTC, Zeeshan Ali
committed Details | Review
wizard: Don't hang on failure to handle a URL (1.28 KB, patch)
2013-08-21 20:43 UTC, Zeeshan Ali
committed Details | Review
wizard: Handle paths as well (1.01 KB, patch)
2013-08-21 20:43 UTC, Zeeshan Ali
committed Details | Review
wizard: Handle local paths to remote files (1.35 KB, patch)
2013-08-21 20:43 UTC, Zeeshan Ali
none Details | Review
app: Minor simplification of code (1.28 KB, patch)
2013-08-22 00:54 UTC, Zeeshan Ali
committed Details | Review
wizard: Handle local paths to remote files (2.47 KB, patch)
2013-08-22 00:55 UTC, Zeeshan Ali
needs-work Details | Review
wizard: Handle local paths to remote files (2.63 KB, patch)
2013-08-22 15:12 UTC, Zeeshan Ali
committed Details | Review

Description Bastien Nocera 2012-11-21 11:07:31 UTC
Further to bug 688797, I passed a local filename to an ISO image (something in /run/user/etc.)

gnome-boxes showed the "analysing media" progress bar:
(gnome-boxes:5041): Boxes-DEBUG: wizard.vala:242: FIXME: application/x-cd-image
but allowed me to select "continue" until I got to a "review" page where the "Create" button spits out warnings:
(gnome-boxes:5041): Boxes-CRITICAL **: boxes_wizard_create_co: assertion `_data_->_tmp1_ != NULL' failed
Comment 1 Alexander Larsson 2013-01-11 10:49:15 UTC
Was it a local file or not? /run/user/ seems to imply a mounted removable media, but thats a local file is it not?
Comment 2 Bastien Nocera 2013-01-11 11:19:08 UTC
(In reply to comment #1)
> Was it a local file or not? /run/user/ seems to imply a mounted removable
> media, but thats a local file is it not?

It was a file on a samba share, and I passed the fuse path to it.
Comment 3 Zeeshan Ali 2013-08-21 13:33:17 UTC
Right, so how do we handle this? Would really want to finally resolve this bug. Should we simply do what we'd do for HTTP URLs? Download first and then use the local copy?
Comment 4 Christophe Fergeau 2013-08-21 13:42:23 UTC
Since it's fuse-mounted, it should more or less behave as a local file, before doing anything special, I'd try to understand why Boxes does not like such mountpoints..
Comment 5 Zeeshan Ali 2013-08-21 14:40:42 UTC
(In reply to comment #4)
> Since it's fuse-mounted, it should more or less behave as a local file, before
> doing anything special, I'd try to understand why Boxes does not like such
> mountpoints..

Right, forgot that the local path is being passed not the gvfs URI. I wonder though if this is really related to file being remote and not that boxes fails on that ISO for some other reason.
Comment 6 Zeeshan Ali 2013-08-21 15:13:00 UTC
After setting up a samba share, I can reproduce the issue but its a different one now in 3.9: Boxes gets stuck at 'Preparation' stage saying "Preparing to create new box" with 0% progress.
Comment 7 Zeeshan Ali 2013-08-21 20:43:15 UTC
Created attachment 252668 [details] [review]
media-manager: Work around vala bug#706517

Its not one of those ugly work arounds and I'm pretty certain some
people will find the resulting code from this minor change, more
readable than before.
Comment 8 Zeeshan Ali 2013-08-21 20:43:19 UTC
Created attachment 252669 [details] [review]
wizard: Don't hang on failure to handle a URL

Boxes would just hang in wizard's preparation stage if you pass a path
to a file on a locally mounted remote share (e.g SMB). Although the real
solution is to be able to handle those, we should have this in place
just in case this codepath is walked for some other reason.
Comment 9 Zeeshan Ali 2013-08-21 20:43:24 UTC
Created attachment 252670 [details] [review]
wizard: Handle paths as well

In commit 3c1b44c, we lost the ability to handle local paths in wizard.
This patch brings back that ability.
Comment 10 Zeeshan Ali 2013-08-21 20:43:29 UTC
Created attachment 252671 [details] [review]
wizard: Handle local paths to remote files

g_file_native() thinks of paths to locally mounted remote locations, as
non-native so Boxes errors out if given such paths. This patch fixes the
issue by replacing g_file_native() usage with a mannual check.
Comment 11 Bastien Nocera 2013-08-21 23:07:49 UTC
(In reply to comment #4)
> Since it's fuse-mounted, it should more or less behave as a local file, before
> doing anything special, I'd try to understand why Boxes does not like such
> mountpoints..

One of the main problems might be that only the user himself can access the gvfs fuse mount, not even root can access it, so it might block any virt code running as root from using that file.
Comment 12 Zeeshan Ali 2013-08-21 23:13:05 UTC
(In reply to comment #11)
> (In reply to comment #4)
> > Since it's fuse-mounted, it should more or less behave as a local file, before
> > doing anything special, I'd try to understand why Boxes does not like such
> > mountpoints..
> 
> One of the main problems might be that only the user himself can access the
> gvfs fuse mount, not even root can access it, so it might block any virt code
> running as root from using that file.

Nah, we use session libvirt so that shouldn't be an issue and the patches I attached should fix the issue. Passing the path through commandline is still broken though and I'm looking into that..
Comment 13 Zeeshan Ali 2013-08-22 00:54:47 UTC
Created attachment 252681 [details] [review]
app: Minor simplification of code
Comment 14 Zeeshan Ali 2013-08-22 00:55:08 UTC
Created attachment 252682 [details] [review]
wizard: Handle local paths to remote files

There are two issues this patch fixes:

* g_file_native() thinks of paths to locally mounted remote locations, as
  non-native so Boxes errors out if given such paths. This patch fixes
  the issue by replacing g_file_native() usage with a mannual check.

* g_file_get_uri() gives us the remote URI even if you created the GFile
  argument using the local path of the remote file. This patch fixes the
  issue by using the original commandline argument if the argument is
  not a path rathan than URI.
Comment 15 Bastien Nocera 2013-08-22 01:01:32 UTC
Review of attachment 252682 [details] [review]:

::: src/app.vala
@@ +293,3 @@
             call_when_ready (() => {
                 var file = File.new_for_commandline_arg (arg);
+                var is_uri = (Uri.parse_scheme (arg) != null);

A relative file on a remote location won't match.

::: src/wizard.vala
@@ +228,3 @@
 
+        var is_uri = location.contains ("://");
+        var file = is_uri? File.new_for_uri (location) : File.new_for_path (location);

Why do you need that? Use File.new_for_commandline_arg instead of hacking around it.

@@ +232,1 @@
+        if (!is_uri || file.has_uri_scheme ("file")) {

Why do you need that? Are you trying to check whether the file is accessible through a file:/// URI? Get the path with g_file_get_path() and transform that to a URI with g_filename_to_uri().
Comment 16 Alexander Larsson 2013-08-22 06:26:30 UTC
Review of attachment 252668 [details] [review]:

yeah, this looks better than before.
Comment 17 Alexander Larsson 2013-08-22 06:32:12 UTC
Review of attachment 252670 [details] [review]:

::: src/wizard.vala
@@ +227,3 @@
             throw new Boxes.Error.INVALID ("empty location");
 
+        var file = location.contains ("://")? File.new_for_uri (location) : File.new_for_path (location);

This seems weird. Where does "location" come from, if its from the commandline (i.e. in the locale encoding) you should use g_file_new_for_commandline_arg, and if its utf8 (from the ui) you should use g_file_parse_name().
Comment 18 Alexander Larsson 2013-08-22 06:35:05 UTC
Review of attachment 252682 [details] [review]:

If you want a path, just use g_file_get_path(), no need for manual uri tweaking (which is bound to go wrong in complex cases).
Comment 19 Alexander Larsson 2013-08-22 06:43:32 UTC
Honestly, I wouldn't trust the fuse/gvfs stuff for passing into libvirt/qemu/etc without testing. Its totally gonna break for e.g. ftp uris. I think we should:

path = g_file_get_path (file);
if (g_file_is_native (file) ||
    (path != NULL &&
     g_file_has_uri_scheme (file, "smb")))
  {
     use path directly
  }
else
  {
     copy file to a local file and use
  }

I.e. only use the direct path for truly local files and for some whitelisted set of tested gvfs backends.
Comment 20 Zeeshan Ali 2013-08-22 11:45:24 UTC
Review of attachment 252682 [details] [review]:

::: src/app.vala
@@ +293,3 @@
             call_when_ready (() => {
                 var file = File.new_for_commandline_arg (arg);
+                var is_uri = (Uri.parse_scheme (arg) != null);

and we don't want to match relative paths here or what did you mean? Example?

::: src/wizard.vala
@@ +228,3 @@
 
+        var is_uri = location.contains ("://");
+        var file = is_uri? File.new_for_uri (location) : File.new_for_path (location);

We used to use that but Alex pointed out how thats wrong for anything that comes from UI: https://bugzilla.gnome.org/show_bug.cgi?id=689840

@@ +232,1 @@
+        if (!is_uri || file.has_uri_scheme ("file")) {

I'm checking if its a local file or not by checking if its not a URI (i-e than its a path) or if its a URI with 'file' scheme.
Comment 21 Zeeshan Ali 2013-08-22 11:52:57 UTC
Review of attachment 252670 [details] [review]:

::: src/wizard.vala
@@ +227,3 @@
             throw new Boxes.Error.INVALID ("empty location");
 
+        var file = location.contains ("://")? File.new_for_uri (location) : File.new_for_path (location);

It can come from both. We used to just use g_file_new_for_commandline_arg() here but I replaced it w/ g_file_new_for_uri(), which fixes filename coming from UI but broken filename coming from commandline.
Comment 22 Zeeshan Ali 2013-08-22 12:28:50 UTC
(In reply to comment #19)
> Honestly, I wouldn't trust the fuse/gvfs stuff for passing into
> libvirt/qemu/etc without testing. Its totally gonna break for e.g. ftp uris. I
> think we should:
> 
> path = g_file_get_path (file);
> if (g_file_is_native (file) ||
>     (path != NULL &&
>      g_file_has_uri_scheme (file, "smb")))
>   {
>      use path directly
>   }
> else
>   {
>      copy file to a local file and use
>   }

Hmm.. I guess it makes sense and I'll trust your opinion on GVFS. I was gonna do the 'else {}' block for remote URIs anyways.
Comment 23 Zeeshan Ali 2013-08-22 15:12:48 UTC
Created attachment 252763 [details] [review]
wizard: Handle local paths to remote files

There are two issues this patch fixes:

* g_file_native() thinks of paths to locally mounted remote locations, as
  non-native so Boxes errors out if given such paths. This patch fixes
  the issue by replacing g_file_native() usage with a mannual check.

* g_file_get_uri() gives us the remote URI even if you created the GFile
  argument using the local path of the remote file. This patch fixes the
  issue by using the original commandline argument if the argument is
  not a path rathan than URI.

Also we restrict the path/URI to filesystems that we know libvirt/qemu
can handle: local and mounted SMB shares.
Comment 24 Zeeshan Ali 2013-08-23 00:08:28 UTC
Pushing these patches. Feel free to still review them and re-open the bug, if needed.

Attachment 252668 [details] pushed as 52ae670 - media-manager: Work around vala bug#706517
Attachment 252669 [details] pushed as 22ff0aa - wizard: Don't hang on failure to handle a URL
Attachment 252670 [details] pushed as 719eacd - wizard: Handle paths as well
Attachment 252681 [details] pushed as 60e4186 - app: Minor simplification of code
Attachment 252763 [details] pushed as e898b44 - wizard: Handle local paths to remote files