Prevent OOB error in addRoomDeltaToResponse

This commit is contained in:
Neil Alexander 2020-01-22 18:04:58 +00:00
parent 86dc91846b
commit 6cea9e8e67

View file

@ -829,9 +829,11 @@ func (d *SyncServerDatasource) addRoomDeltaToResponse(
// Retrieve the backward topology position, i.e. the position of the // Retrieve the backward topology position, i.e. the position of the
// oldest event in the room's topology. // oldest event in the room's topology.
var backwardTopologyPos types.StreamPosition var backwardTopologyPos types.StreamPosition
backwardTopologyPos, err = d.topology.selectPositionInTopology(ctx, recentStreamEvents[0].EventID()) if len(recentStreamEvents) > 0 {
if err != nil { backwardTopologyPos, err = d.topology.selectPositionInTopology(ctx, recentStreamEvents[0].EventID())
return err if err != nil {
return err
}
} }
if backwardTopologyPos-1 <= 0 { if backwardTopologyPos-1 <= 0 {
backwardTopologyPos = types.StreamPosition(1) backwardTopologyPos = types.StreamPosition(1)