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.

   <type 'exceptions.OverflowError'>: 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.
This commit is contained in:
Calum Lind 2018-10-19 17:28:31 +01:00
commit d85f665091
5 changed files with 17 additions and 5 deletions

View file

@ -747,7 +747,8 @@ class Torrent(object):
if left > 0: if left > 0:
eta = left // status.download_payload_rate 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): def get_ratio(self):
"""Get the ratio of upload/download for this torrent. """Get the ratio of upload/download for this torrent.

View file

@ -31,8 +31,10 @@ def format_speed(speed):
def format_time(time): def format_time(time):
if time > 0: if time > 0:
return deluge.common.ftime(time) return deluge.common.ftime(time)
else: elif time == 0:
return '-' return '-'
else:
return ''
def format_date_dash(time): def format_date_dash(time):

View file

@ -50,7 +50,12 @@ def fdate_or_dash(value):
def ftime_or_dash(value): def ftime_or_dash(value):
"""Display value as time, eg 2h 30m or dash""" """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): def fseed_rank_or_dash(seed_rank, seeding_time):

View file

@ -74,6 +74,10 @@
return date > 0.0 ? fdate(date) : _('Never'); return date > 0.0 ? fdate(date) : _('Never');
} }
function timeOrInf(time) {
return time < 0 ? '&infin;' : ftime(time);
}
/** /**
* Deluge.TorrentGrid Class * Deluge.TorrentGrid Class
* *
@ -154,7 +158,7 @@
header: _('ETA'), header: _('ETA'),
width: 60, width: 60,
sortable: true, sortable: true,
renderer: ftime, renderer: timeOrInf,
dataIndex: 'eta', dataIndex: 'eta',
}, },
{ {

View file

@ -102,7 +102,7 @@ Deluge.details.StatusTab = Ext.extend(Ext.Panel, {
upspeed: status.upload_payload_rate upspeed: status.upload_payload_rate
? fspeed(status.upload_payload_rate) ? fspeed(status.upload_payload_rate)
: '0.0 KiB/s', : '0.0 KiB/s',
eta: ftime(status.eta), eta: status.eta < 0 ? '&infin;' : ftime(status.eta),
pieces: status.num_pieces + ' (' + fsize(status.piece_length) + ')', pieces: status.num_pieces + ' (' + fsize(status.piece_length) + ')',
seeds: seeds, seeds: seeds,
peers: peers, peers: peers,