Be a little more careful to handle exceptions from boost::filesystem::file_size
authorCarl Hetherington <cth@carlh.net>
Mon, 29 Nov 2021 23:00:17 +0000 (00:00 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 29 Nov 2021 23:01:29 +0000 (00:01 +0100)
There has been a report of file_size throwing an exception and
crashing DCP-o-matic, but I haven't been able to reproduce it yet
(possibly related to there being missing content files).

src/lib/file_log.cc
src/wx/config_dialog.cc

index 5cc9c556942b4868de44a835ce305f2b0eebab12..4d6a0e6ea39fd67b7b13ea40fc7a7f475a227826 100644 (file)
@@ -69,7 +69,11 @@ FileLog::head_and_tail (int amount) const
 
        uintmax_t head_amount = amount;
        uintmax_t tail_amount = amount;
 
        uintmax_t head_amount = amount;
        uintmax_t tail_amount = amount;
-       uintmax_t size = boost::filesystem::file_size (_file);
+       boost::system::error_code ec;
+       uintmax_t size = boost::filesystem::file_size (_file, ec);
+       if (size == static_cast<uintmax_t>(-1)) {
+               return "";
+       }
 
        if (size < (head_amount + tail_amount)) {
                head_amount = size;
 
        if (size < (head_amount + tail_amount)) {
                head_amount = size;
index 53c67d101d8e611dca2c101fbafe576d7c696686..e0effec53eafb90a25d2ff2e966f9d92f90406d7 100644 (file)
@@ -633,7 +633,7 @@ CertificateChainEditor::import_private_key ()
                        chain->set_key (dcp::file_to_string (p));
                        _set (chain);
                        update_private_key ();
                        chain->set_key (dcp::file_to_string (p));
                        _set (chain);
                        update_private_key ();
-               } catch (dcp::MiscError& e) {
+               } catch (std::exception& e) {
                        error_dialog (this, _("Could not read certificate file."), std_to_wx(e.what()));
                }
        }
                        error_dialog (this, _("Could not read certificate file."), std_to_wx(e.what()));
                }
        }