mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Fix TimeSpan overflow on Read (#6170)
A lot of areas use TimeSpan.MaxValue but when saved and read the current time is added which results in an overflow. A check is now performed to prevent this.
This commit is contained in:
@@ -37,7 +37,13 @@ public sealed class TimeOffsetSerializer : ITypeSerializer<TimeSpan, ValueDataNo
|
||||
|
||||
var timing = ctx.Timing;
|
||||
var seconds = double.Parse(node.Value, CultureInfo.InvariantCulture);
|
||||
return TimeSpan.FromSeconds(seconds) + timing.CurTime;
|
||||
var time = TimeSpan.FromSeconds(seconds);
|
||||
|
||||
// Checks if adding time and curTime will overflow.
|
||||
if(time > TimeSpan.MaxValue - timing.CurTime)
|
||||
return TimeSpan.MaxValue;
|
||||
|
||||
return time + timing.CurTime;
|
||||
}
|
||||
|
||||
public ValidationNode Validate(ISerializationManager serializationManager, ValueDataNode node,
|
||||
|
||||
Reference in New Issue
Block a user