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
=== modified file 'src/View/ViewContainer.vala'
--- src/View/ViewContainer.vala 2014-08-03 14:05:45 +0000
+++ src/View/ViewContainer.vala 2014-10-15 12:45:45 +0000
@@ -355,7 +355,7 @@
355 dir.cancel ();355 dir.cancel ();
356 dir.need_reload.disconnect (reload);356 dir.need_reload.disconnect (reload);
357 dir.remove_dir_from_cache ();357 dir.remove_dir_from_cache ();
358 change_view (view_mode, null);358 dir.load ();
359 }359 }
360360
361 public void update_location_state (bool save_history) {361 public void update_location_state (bool save_history) {
362362
=== modified file 'src/View/Window.vala'
--- src/View/Window.vala 2014-08-01 20:20:07 +0000
+++ src/View/Window.vala 2014-10-15 12:45:45 +0000
@@ -521,7 +521,15 @@
521 if (viewmode < 0 || viewmode > 2 || root_uri == null || root_uri == "" || tip_uri == null)521 if (viewmode < 0 || viewmode > 2 || root_uri == null || root_uri == "" || tip_uri == null)
522 continue;522 continue;
523523
524 GLib.File root_location = GLib.File.new_for_uri (GLib.Uri.unescape_string (root_uri));524 string? unescaped_root_uri = GLib.Uri.unescape_string (root_uri);
525 if (unescaped_root_uri == null) {
526 warning ("Invalid root location for tab");
527 continue;
528 }
529
530 GLib.File root_location = GLib.File.new_for_uri (unescaped_root_uri);
531 if (!valid_location (root_location))
532 continue;
525533
526 add_tab (root_location, viewmode);534 add_tab (root_location, viewmode);
527535
@@ -542,9 +550,14 @@
542 change_tab (active_tab_position);550 change_tab (active_tab_position);
543 }551 }
544552
545 string path = current_tab.get_tip_uri ();553 string path;
546 if (path == "")554 if (current_tab == null)
547 path = current_tab.get_root_uri ();555 path = "";
556 else {
557 path = current_tab.get_tip_uri ();
558 if (path == "")
559 path = current_tab.get_root_uri ();
560 }
548561
549 /* Render the final path in the location bar without animation */562 /* Render the final path in the location bar without animation */
550 top_menu.location_bar.bread.animation_visible = false;563 top_menu.location_bar.bread.animation_visible = false;
@@ -554,11 +567,35 @@
554 return tabs_added;567 return tabs_added;
555 }568 }
556569
570 private bool valid_location (GLib.File location) {
571 GLib.FileInfo? info = null;
572 try {
573 info = location.query_info ("standard::*", GLib.FileQueryInfoFlags.NONE);
574 }
575 catch (GLib.Error e) {
576 warning ("Invalid location on restoring tabs");
577 return false;
578 }
579
580 if (info.get_file_type () == GLib.FileType.DIRECTORY)
581 return true;
582 else {
583 warning ("Attempt to restore a location that is not a directory");
584 return false;
585 }
586 }
587
557 private void expand_miller_view (string tip_uri, GLib.File root_location) {588 private void expand_miller_view (string tip_uri, GLib.File root_location) {
558 var tab = tabs.current;589 var tab = tabs.current;
559 var view = tab.page as ViewContainer;590 var view = tab.page as ViewContainer;
560 var mwcols = view.mwcol;591 var mwcols = view.mwcol;
561 var unescaped_tip_uri = GLib.Uri.unescape_string (tip_uri);592 string? unescaped_tip_uri = GLib.Uri.unescape_string (tip_uri);
593
594 if (unescaped_tip_uri == null) {
595 warning ("Invalid tip uri for Miller View");
596 return;
597 }
598
562 var tip_location = GLib.File.new_for_uri (unescaped_tip_uri);599 var tip_location = GLib.File.new_for_uri (unescaped_tip_uri);
563 var relative_path = root_location.get_relative_path (tip_location);600 var relative_path = root_location.get_relative_path (tip_location);
564 var slot = mwcols.active_slot;601 var slot = mwcols.active_slot;
@@ -573,6 +610,9 @@
573 foreach (string dir in dirs) {610 foreach (string dir in dirs) {
574 uri += (GLib.Path.DIR_SEPARATOR_S + dir);611 uri += (GLib.Path.DIR_SEPARATOR_S + dir);
575 gfile = GLib.File.new_for_uri (uri);612 gfile = GLib.File.new_for_uri (uri);
613 if (!valid_location (gfile))
614 break;
615
576 dview = slot.view_box as FM.Directory.View;616 dview = slot.view_box as FM.Directory.View;
577617
578 dview.column_add_location (gfile);618 dview.column_add_location (gfile);

Subscribers

People subscribed via source and target branches

to all changes: