From d85f665091e01f585beae3332404086480eb7005 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Fri, 19 Oct 2018 17:28:31 +0100 Subject: [PATCH] Fix large ETA overflow C int The following error was encountered in GTK3 which is a result of trying to cast a very large ETA value to C int and raising an Overlflow error. : 3072227291 not in range -2147483648 to 2147483647 The solution is to limit the ETA to 1 year and represent any values over that as -1 which the UIs can display as infinity. --- deluge/core/torrent.py | 3 ++- deluge/ui/console/utils/format_utils.py | 4 +++- deluge/ui/gtkui/tab_data_funcs.py | 7 ++++++- deluge/ui/web/js/deluge-all/TorrentGrid.js | 6 +++++- deluge/ui/web/js/deluge-all/details/StatusTab.js | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 12b30a45c..c9cd16ae3 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -747,7 +747,8 @@ class Torrent(object): if left > 0: eta = left // status.download_payload_rate - return eta + # Limit to 1 year, avoid excessive values and prevent GTK int overflow. + return eta if eta < 31557600 else -1 def get_ratio(self): """Get the ratio of upload/download for this torrent. diff --git a/deluge/ui/console/utils/format_utils.py b/deluge/ui/console/utils/format_utils.py index 6b6d8d483..029fb2011 100644 --- a/deluge/ui/console/utils/format_utils.py +++ b/deluge/ui/console/utils/format_utils.py @@ -31,8 +31,10 @@ def format_speed(speed): def format_time(time): if time > 0: return deluge.common.ftime(time) - else: + elif time == 0: return '-' + else: + return '∞' def format_date_dash(time): diff --git a/deluge/ui/gtkui/tab_data_funcs.py b/deluge/ui/gtkui/tab_data_funcs.py index 796091f35..020651dcb 100644 --- a/deluge/ui/gtkui/tab_data_funcs.py +++ b/deluge/ui/gtkui/tab_data_funcs.py @@ -50,7 +50,12 @@ def fdate_or_dash(value): def ftime_or_dash(value): """Display value as time, eg 2h 30m or dash""" - return ftime(value) if value > 0 else '-' + if value > 0: + return ftime(value) + elif value == 0: + return '-' + else: + return '∞' def fseed_rank_or_dash(seed_rank, seeding_time): diff --git a/deluge/ui/web/js/deluge-all/TorrentGrid.js b/deluge/ui/web/js/deluge-all/TorrentGrid.js index c6559d443..b0e0c5ec7 100644 --- a/deluge/ui/web/js/deluge-all/TorrentGrid.js +++ b/deluge/ui/web/js/deluge-all/TorrentGrid.js @@ -74,6 +74,10 @@ return date > 0.0 ? fdate(date) : _('Never'); } + function timeOrInf(time) { + return time < 0 ? '∞' : ftime(time); + } + /** * Deluge.TorrentGrid Class * @@ -154,7 +158,7 @@ header: _('ETA'), width: 60, sortable: true, - renderer: ftime, + renderer: timeOrInf, dataIndex: 'eta', }, { diff --git a/deluge/ui/web/js/deluge-all/details/StatusTab.js b/deluge/ui/web/js/deluge-all/details/StatusTab.js index 864afce1c..a8753bb87 100644 --- a/deluge/ui/web/js/deluge-all/details/StatusTab.js +++ b/deluge/ui/web/js/deluge-all/details/StatusTab.js @@ -102,7 +102,7 @@ Deluge.details.StatusTab = Ext.extend(Ext.Panel, { upspeed: status.upload_payload_rate ? fspeed(status.upload_payload_rate) : '0.0 KiB/s', - eta: ftime(status.eta), + eta: status.eta < 0 ? '∞' : ftime(status.eta), pieces: status.num_pieces + ' (' + fsize(status.piece_length) + ')', seeds: seeds, peers: peers,