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 704990 - Validate input when opening files
Validate input when opening files
Status: RESOLVED FIXED
Product: gnome-chess
Classification: Applications
Component: General
3.9.x
Other Linux
: High critical
: ---
Assigned To: Sahil Sareen
gnome-chess-maint
Depends on: 745024
Blocks:
 
 
Reported: 2013-07-27 15:13 UTC by Michael Catanzaro
Modified: 2015-04-21 14:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test Golbat (48.22 KB, image/png)
2013-07-27 15:13 UTC, Michael Catanzaro
  Details
Allow loading only pgn files to avoid crashes (1.01 KB, patch)
2014-12-30 15:56 UTC, Sahil Sareen
none Details | Review
Test Golbat #2 (48.22 KB, application/octet-stream)
2014-12-30 17:04 UTC, Michael Catanzaro
  Details
Validate PGN (2.32 KB, patch)
2015-04-17 13:55 UTC, Sahil Sareen
none Details | Review
Validate PGN (1.86 KB, patch)
2015-04-17 17:50 UTC, Sahil Sareen
accepted-commit_now Details | Review
Validate PGN (1.87 KB, patch)
2015-04-21 14:18 UTC, Sahil Sareen
accepted-commit_now Details | Review

Description Michael Catanzaro 2013-07-27 15:13:40 UTC
Created attachment 250267 [details]
Test Golbat

If you're stupid and try to open something that's not a PGN, you're likely to crash GNOME Chess.  We need better input validation.  Test file attached.
Comment 1 Sahil Sareen 2014-12-30 15:56:54 UTC
Created attachment 293482 [details] [review]
Allow loading only pgn files to avoid crashes

1. Would it be a good idea to allow loading only pgn files?[patch]

2. Does this bug mean to address validating the moves as well along with all the initial fields in the pgn file?
Comment 2 Michael Catanzaro 2014-12-30 17:04:19 UTC
Created attachment 293485 [details]
Test Golbat #2

> 1. Would it be a good idea to allow loading only pgn files?[patch]

No, because then I can still crash Chess just by changing the file extension. :)  To fix this bug, look at the backtrace of the crash to see why the crash occurred, then display a warning dialog ("Uh-oh! This doesn't look like a valid chess game log.") instead of crashing.

[New LWP 23602]
[New LWP 23603]
[New LWP 23604]
[New LWP 23606]
[New LWP 23619]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `gnome-chess'.
Program terminated with signal SIGSEGV, Segmentation fault.

Thread 1 (Thread 0x7fbe1df97980 (LWP 23602))

  • #0 chess_application_start_game
    at /home/mcatanzaro/jhbuild/checkout/gnome-chess/src/gnome-chess.vala line 448
  • #1 chess_application_load_game
    at /home/mcatanzaro/jhbuild/checkout/gnome-chess/src/gnome-chess.vala line 2251
  • #2 chess_application_open_dialog_cb
    at /home/mcatanzaro/jhbuild/checkout/gnome-chess/src/gnome-chess.vala line 2180
  • #3 g_closure_invoke
    at gclosure.c line 768
  • #4 signal_emit_unlocked_R
    at gsignal.c line 3553
  • #5 g_signal_emit_valist
    at gsignal.c line 3309
  • #6 g_signal_emit_by_name
    at gsignal.c line 3405
  • #7 g_closure_invoke
    at gclosure.c line 768
  • #8 signal_emit_unlocked_R
    at gsignal.c line 3553
  • #9 g_signal_emit_valist
    at gsignal.c line 3309
  • #10 g_signal_emit_by_name
    at gsignal.c line 3405
  • #11 list_row_activated
    at gtkfilechooserwidget.c line 6732
  • #12 g_closure_invoke
    at gclosure.c line 768
  • #13 signal_emit_unlocked_R
    at gsignal.c line 3553
  • #14 g_signal_emit_valist
    at gsignal.c line 3309
  • #15 g_signal_emit
    at gsignal.c line 3365
  • #16 gtk_tree_view_multipress_gesture_pressed
    at gtktreeview.c line 3295
  • #17 ffi_call_unix64
    at ../src/x86/unix64.S line 76
  • #18 ffi_call
    at ../src/x86/ffi64.c line 525
  • #19 g_cclosure_marshal_generic_va
    at gclosure.c line 1541
  • #20 _g_closure_invoke_va
    at gclosure.c line 831
  • #21 g_signal_emit_valist
    at gsignal.c line 3218
  • #22 g_signal_emit
    at gsignal.c line 3365
  • #23 gtk_gesture_multi_press_begin
    at gtkgesturemultipress.c line 232
  • #24 g_cclosure_marshal_VOID__BOXEDv
    at gmarshal.c line 1160
  • #25 _g_closure_invoke_va
    at gclosure.c line 831
  • #26 g_signal_emit_valist
    at gsignal.c line 3218
  • #27 g_signal_emit
    at gsignal.c line 3365
  • #28 _gtk_gesture_set_recognized
    at gtkgesture.c line 273
  • #29 _gtk_gesture_check_recognized
    at gtkgesture.c line 318
  • #30 gtk_gesture_handle_event
    at gtkgesture.c line 598
  • #31 gtk_gesture_single_handle_event
    at gtkgesturesingle.c line 218
  • #32 gtk_event_controller_handle_event
    at gtkeventcontroller.c line 214
  • #33 _gtk_widget_run_controllers
    at gtkwidget.c line 7428
  • #34 _gtk_marshal_BOOLEAN__BOXED
    at gtkmarshalers.c line 85
  • #35 g_closure_invoke
    at gclosure.c line 768
  • #36 signal_emit_unlocked_R
    at gsignal.c line 3591
  • #37 g_signal_emit_valist
    at gsignal.c line 3319
  • #38 g_signal_emit
    at gsignal.c line 3365
  • #39 gtk_widget_event_internal
    at gtkwidget.c line 7773
  • #40 propagate_event_up
    at gtkmain.c line 2414
  • #41 propagate_event
    at gtkmain.c line 2516
  • #42 gtk_main_do_event
    at gtkmain.c line 1748
  • #43 gdk_event_source_dispatch
    at gdkeventsource.c line 364
  • #44 g_main_dispatch
    at gmain.c line 3111
  • #45 g_main_context_dispatch
    at gmain.c line 3710
  • #46 g_main_context_iterate
    at gmain.c line 3781
  • #47 g_main_context_iteration
    at gmain.c line 3842
  • #48 g_application_run
    at gapplication.c line 2282
  • #49 chess_application_main
    at /home/mcatanzaro/jhbuild/checkout/gnome-chess/src/gnome-chess.vala line 2266
  • #50 __libc_start_main
    at libc-start.c line 289
  • #51 _start

Comment 3 Michael Catanzaro 2014-12-30 17:07:07 UTC
Oh, and that trace was taken on 3.14.1. The crash occurred in gnome-chess.vala:448, which is:

string[] moves = new string[pgn_game.moves.length ()];
Comment 4 Sahil Sareen 2015-04-17 13:55:11 UTC
Created attachment 301841 [details] [review]
Validate PGN

Display a dialog telling the player if he tries to load an invalid PGN file.
Made sure that the game_file is set to null to avoid setting the filename in the header bar.
Comment 5 Michael Catanzaro 2015-04-17 15:06:11 UTC
Review of attachment 301841 [details] [review]:

Nits:

::: src/gnome-chess.vala
@@ +36,2 @@
     private Gtk.Dialog? preferences_dialog = null;
+    private Gtk.Dialog? invalid_pgn_dialog = null;

Since it's used only in one function, it doesn't need to be a member variable, correct?

@@ +2144,3 @@
     }
 
+    public void invalid_pgn_draw_dialog ()

Since you're not mucking with Cairo, I wouldn't include "draw" in the name of the function. Perhaps run_invalid_pgn_dialog()?

Also, it can be private, right?

@@ +2154,3 @@
+        var invalid_pgn_dialog = new Gtk.MessageDialog (window,
+                                                       Gtk.DialogFlags.MODAL,
+                                                       Gtk.MessageType.QUESTION,

Gtk.MessageType.ERROR (or maybe Gtk.MessageType.WARNING)

@@ +2443,3 @@
+            pgn_game = new PGNGame ();
+            game_file = null;
+        } else {

I think we always have opening bracket on the next line in Chess. (Why didn't your script catch this? :-)
Comment 6 Sahil Sareen 2015-04-17 17:50:33 UTC
Created attachment 301867 [details] [review]
Validate PGN
Comment 7 Sahil Sareen 2015-04-17 17:52:44 UTC
(In reply to Michael Catanzaro from comment #5)
> I think we always have opening bracket on the next line in Chess. (Why
> didn't your script catch this? :-)

The script doesn't check this yet, 
The reason I didn't put this check in was because I wasn't sure if it applies to all games. 

Should be straight forward to add though.
Comment 8 Michael Catanzaro 2015-04-17 18:42:06 UTC
Review of attachment 301867 [details] [review]:

::: src/gnome-chess.vala
@@ +2145,3 @@
+    private void run_invalid_pgn_dialog ()
+    {
+        Gtk.Dialog? invalid_pgn_dialog = new Gtk.MessageDialog (window,

OK, but now it should not be nullable because it should never be null. :) Accepted with that tweak.

Actually, we normally use the var keyword whenever possible, so I would use that instead.
Comment 9 Michael Catanzaro 2015-04-17 18:43:22 UTC
Also, all Vala games except Sudoku use the same style. But Sudoku is internally inconsistent, so at some point we'll want to fix that anyway.
Comment 10 Sahil Sareen 2015-04-21 14:18:30 UTC
Created attachment 302072 [details] [review]
Validate PGN

Changed to 'var'.
Comment 11 Sahil Sareen 2015-04-21 14:20:36 UTC
(In reply to Michael Catanzaro from comment #9)
> Also, all Vala games except Sudoku use the same style. But Sudoku is
> internally inconsistent, so at some point we'll want to fix that anyway.

I'll take care of that by tomorrow EOD and then update the script to check brackets.
Comment 12 Sahil Sareen 2015-04-21 14:20:54 UTC
Fix pushed to master.

To ssh://ssareen@git.gnome.org/git/gnome-chess
   ba128dd..0fbed8d  master -> master