Fix: values above INT_MAX (68 years) are interpreted as negative values (#4085)

This commit is contained in:
A Cœur 2022-11-07 22:27:51 +08:00 committed by GitHub
parent fd7bb4a287
commit 69ee92113f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 10 deletions

View File

@ -2068,20 +2068,16 @@ bool trashDataFile(char const* filename, void* /*user_data*/, tr_error** error)
- (NSString*)etaString
{
NSInteger eta;
BOOL fromIdle;
//don't check for both, since if there's a regular ETA, the torrent isn't idle so it's meaningless
if (self.fStat->eta != TR_ETA_NOT_AVAIL && self.fStat->eta != TR_ETA_UNKNOWN)
{
eta = self.fStat->eta;
fromIdle = NO;
}
else if (self.fStat->etaIdle != TR_ETA_NOT_AVAIL && self.fStat->etaIdle < kETAIdleDisplaySec)
time_t eta = self.fStat->eta;
// if there's a regular ETA, the torrent isn't idle
BOOL fromIdle = NO;
if (eta == TR_ETA_NOT_AVAIL || eta == TR_ETA_UNKNOWN)
{
eta = self.fStat->etaIdle;
fromIdle = YES;
}
else
// Foundation undocumented behavior: values above INT_MAX (68 years) are interpreted as negative values by `stringFromTimeInterval` (#3451)
if (eta < 0 || eta > INT_MAX || (fromIdle && eta >= kETAIdleDisplaySec))
{
return NSLocalizedString(@"remaining time unknown", "Torrent -> eta string");
}
@ -2095,6 +2091,8 @@ bool trashDataFile(char const* filename, void* /*user_data*/, tr_error** error)
formatter.collapsesLargestUnit = YES;
formatter.includesTimeRemainingPhrase = YES;
});
// the duration of months being variable, setting the reference date to now (instead of 00:00:00 UTC on 1 January 2001)
formatter.referenceDate = NSDate.date;
NSString* idleString = [formatter stringFromTimeInterval:eta];
if (fromIdle)