Skip to content

Commit 68a5e1c

Browse files
committed
[bugfix] Avoid integer overflows for published times
1 parent 93ff003 commit 68a5e1c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

internal/app/controller/engine.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ func (e *Engine) updateTimes(currentTime time.Time, delta time.Duration) (timeCh
193193
newCurrentActionTimeRemaining := e.State.CurrentActionDeadline.Sub(currentTime)
194194
timeChanged = timeChanged || isNewFullSecond(e.State.CurrentActionTimeRemaining, newCurrentActionTimeRemaining-e.State.CurrentActionTimeRemaining)
195195
e.State.CurrentActionTimeRemaining = newCurrentActionTimeRemaining
196+
minimumTimeRemaining := -time.Minute * 30
197+
if e.State.CurrentActionTimeRemaining < minimumTimeRemaining {
198+
// limit how small this time can get to avoid overflow in referee message
199+
e.State.CurrentActionTimeRemaining = minimumTimeRemaining
200+
}
196201
}
197202

198203
return

internal/app/controller/publisher.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,17 @@ func (p *RefMessage) updateTeam(teamInfo *refproto.Referee_TeamInfo, state *Team
249249
teamInfo.YellowCardTimes = mapTimes(state.YellowCardTimes)
250250
*teamInfo.YellowCards = uint32(state.YellowCards)
251251
*teamInfo.Timeouts = uint32(state.TimeoutsLeft)
252-
*teamInfo.TimeoutTime = uint32(state.TimeoutTimeLeft.Nanoseconds() / 1000)
253252
*teamInfo.Goalkeeper = uint32(state.Goalkeeper)
254253
*teamInfo.FoulCounter = uint32(state.FoulCounter)
255254
*teamInfo.BallPlacementFailures = uint32(state.BallPlacementFailures)
256255
*teamInfo.CanPlaceBall = state.CanPlaceBall
257256
*teamInfo.MaxAllowedBots = uint32(state.MaxAllowedBots)
257+
258+
if state.TimeoutTimeLeft.Nanoseconds() > 0 {
259+
*teamInfo.TimeoutTime = uint32(state.TimeoutTimeLeft.Nanoseconds() / 1000)
260+
} else {
261+
*teamInfo.TimeoutTime = 0
262+
}
258263
}
259264

260265
func mapTimes(durations []time.Duration) []uint32 {

0 commit comments

Comments
 (0)