Merge lp:~jeremywootten/pantheon-files/fix-crash-on-restore-tabs into lp:~elementary-apps/pantheon-files/trunk

Proposed by Jeremy Wootten
Status: Merged
Approved by: Cody Garver
Approved revision: 1614
Merged at revision: 1618
Proposed branch: lp:~jeremywootten/pantheon-files/fix-crash-on-restore-tabs
Merge into: lp:~elementary-apps/pantheon-files/trunk
Diff against target: 98 lines (+46/-6)
2 files modified
src/View/ViewContainer.vala (+1/-1)
src/View/Window.vala (+45/-5)
To merge this branch: bzr merge lp:~jeremywootten/pantheon-files/fix-crash-on-restore-tabs
Reviewer Review Type Date Requested Status
elementary Apps team Pending
Review via email: mp+238430@code.launchpad.net

Commit message

More carefully validate URIs when restoring tabs

Description of the change

This branch includes some extra checks on uris retrieved from settings during restore tabs.
The uris must be valid and correspond to existing directories.
I have not been able to reproduce the bug but this should reduce the likelihood of it occuring.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/View/ViewContainer.vala'
2--- src/View/ViewContainer.vala 2014-08-03 14:05:45 +0000
3+++ src/View/ViewContainer.vala 2014-10-15 12:45:45 +0000
4@@ -355,7 +355,7 @@
5 dir.cancel ();
6 dir.need_reload.disconnect (reload);
7 dir.remove_dir_from_cache ();
8- change_view (view_mode, null);
9+ dir.load ();
10 }
11
12 public void update_location_state (bool save_history) {
13
14=== modified file 'src/View/Window.vala'
15--- src/View/Window.vala 2014-08-01 20:20:07 +0000
16+++ src/View/Window.vala 2014-10-15 12:45:45 +0000
17@@ -521,7 +521,15 @@
18 if (viewmode < 0 || viewmode > 2 || root_uri == null || root_uri == "" || tip_uri == null)
19 continue;
20
21- GLib.File root_location = GLib.File.new_for_uri (GLib.Uri.unescape_string (root_uri));
22+ string? unescaped_root_uri = GLib.Uri.unescape_string (root_uri);
23+ if (unescaped_root_uri == null) {
24+ warning ("Invalid root location for tab");
25+ continue;
26+ }
27+
28+ GLib.File root_location = GLib.File.new_for_uri (unescaped_root_uri);
29+ if (!valid_location (root_location))
30+ continue;
31
32 add_tab (root_location, viewmode);
33
34@@ -542,9 +550,14 @@
35 change_tab (active_tab_position);
36 }
37
38- string path = current_tab.get_tip_uri ();
39- if (path == "")
40- path = current_tab.get_root_uri ();
41+ string path;
42+ if (current_tab == null)
43+ path = "";
44+ else {
45+ path = current_tab.get_tip_uri ();
46+ if (path == "")
47+ path = current_tab.get_root_uri ();
48+ }
49
50 /* Render the final path in the location bar without animation */
51 top_menu.location_bar.bread.animation_visible = false;
52@@ -554,11 +567,35 @@
53 return tabs_added;
54 }
55
56+ private bool valid_location (GLib.File location) {
57+ GLib.FileInfo? info = null;
58+ try {
59+ info = location.query_info ("standard::*", GLib.FileQueryInfoFlags.NONE);
60+ }
61+ catch (GLib.Error e) {
62+ warning ("Invalid location on restoring tabs");
63+ return false;
64+ }
65+
66+ if (info.get_file_type () == GLib.FileType.DIRECTORY)
67+ return true;
68+ else {
69+ warning ("Attempt to restore a location that is not a directory");
70+ return false;
71+ }
72+ }
73+
74 private void expand_miller_view (string tip_uri, GLib.File root_location) {
75 var tab = tabs.current;
76 var view = tab.page as ViewContainer;
77 var mwcols = view.mwcol;
78- var unescaped_tip_uri = GLib.Uri.unescape_string (tip_uri);
79+ string? unescaped_tip_uri = GLib.Uri.unescape_string (tip_uri);
80+
81+ if (unescaped_tip_uri == null) {
82+ warning ("Invalid tip uri for Miller View");
83+ return;
84+ }
85+
86 var tip_location = GLib.File.new_for_uri (unescaped_tip_uri);
87 var relative_path = root_location.get_relative_path (tip_location);
88 var slot = mwcols.active_slot;
89@@ -573,6 +610,9 @@
90 foreach (string dir in dirs) {
91 uri += (GLib.Path.DIR_SEPARATOR_S + dir);
92 gfile = GLib.File.new_for_uri (uri);
93+ if (!valid_location (gfile))
94+ break;
95+
96 dview = slot.view_box as FM.Directory.View;
97
98 dview.column_add_location (gfile);

Subscribers

People subscribed via source and target branches

to all changes: