From 97d45c7c300c3e0e753530266d831028c9347f03 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sun, 5 Nov 2017 22:33:19 +0100 Subject: [PATCH 1/3] fix typo: text gui with no wallet --- gui/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/text.py b/gui/text.py index 391e445d..2e613066 100644 --- a/gui/text.py +++ b/gui/text.py @@ -25,7 +25,7 @@ class ElectrumGui: self.config = config self.network = daemon.network storage = WalletStorage(config.get_wallet_path()) - if not storage.file_exists: + if not storage.file_exists(): print("Wallet not found. try 'electrum create'") exit() if storage.is_encrypted(): From b28f8b3ebd7f00eb69216e1a7ea4c6ae241ee519 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 6 Nov 2017 12:27:47 +0100 Subject: [PATCH 2/3] make tx deserialization more robust to ill-formed tx --- gui/qt/main_window.py | 20 ++++++++++++++------ lib/transaction.py | 33 ++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index c2cfb06e..1cfd6e67 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -2119,17 +2119,25 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): return self.tx_from_text(file_content) def do_process_from_text(self): + from electrum.transaction import SerializationError text = text_dialog(self, _('Input raw transaction'), _("Transaction:"), _("Load transaction")) if not text: return - tx = self.tx_from_text(text) - if tx: - self.show_transaction(tx) + try: + tx = self.tx_from_text(text) + if tx: + self.show_transaction(tx) + except SerializationError as e: + self.show_critical(_("Electrum was unable to deserialize the transaction:") + "\n" + str(e)) def do_process_from_file(self): - tx = self.read_tx_from_file() - if tx: - self.show_transaction(tx) + from electrum.transaction import SerializationError + try: + tx = self.read_tx_from_file() + if tx: + self.show_transaction(tx) + except SerializationError as e: + self.show_critical(_("Electrum was unable to deserialize the transaction:") + "\n" + str(e)) def do_process_from_txid(self): from electrum import transaction diff --git a/lib/transaction.py b/lib/transaction.py index b5094738..eec28744 100644 --- a/lib/transaction.py +++ b/lib/transaction.py @@ -77,10 +77,7 @@ class BCDataStream(object): if self.input is None: raise SerializationError("call write(bytes) before trying to deserialize") - try: - length = self.read_compact_size() - except IndexError: - raise SerializationError("attempt to read past end of buffer") + length = self.read_compact_size() return self.read_bytes(length).decode(encoding) @@ -117,15 +114,18 @@ class BCDataStream(object): def write_uint64(self, val): return self._write_num(' Date: Mon, 6 Nov 2017 12:44:36 +0100 Subject: [PATCH 3/3] fix tests --- lib/tests/test_transaction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tests/test_transaction.py b/lib/tests/test_transaction.py index 388f45e2..d1d3cc6c 100644 --- a/lib/tests/test_transaction.py +++ b/lib/tests/test_transaction.py @@ -30,7 +30,7 @@ class TestBCDataStream(unittest.TestCase): for v in values: self.assertEqual(s.read_compact_size(), v) - with self.assertRaises(IndexError): + with self.assertRaises(transaction.SerializationError): s.read_compact_size() def test_string(self):