Skip to content

Commit e108bb9

Browse files
BufferedEvents Read Path Protections (#709)
* Discard and log persisted nil buffered events on read path * Add nil safety checks to statsComputer
1 parent 7f44f34 commit e108bb9

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

common/persistence/executionStore.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ func (m *executionManagerImpl) DeserializeBufferedEvents(
182182

183183
events := make([]*historypb.HistoryEvent, 0)
184184
for _, b := range blobs {
185+
if b == nil {
186+
// Should not happen, log and discard to prevent callers from consuming
187+
m.logger.Warn("discarding nil buffered event")
188+
continue
189+
}
190+
185191
history, err := m.serializer.DeserializeBatchEvents(b)
186192
if err != nil {
187193
return nil, err

common/persistence/statsComputer.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ func (sc *statsComputer) computeMutableStateStats(req *InternalGetWorkflowExecut
6767

6868
for _, be := range req.State.BufferedEvents {
6969
bufferedEventsCount++
70+
71+
if be == nil {
72+
continue
73+
}
74+
7075
bufferedEventsSize += len(be.Data)
7176
}
7277

@@ -182,6 +187,10 @@ func (sc *statsComputer) computeMutableStateUpdateStats(req *InternalUpdateWorkf
182187
}
183188

184189
func computeExecutionInfoSize(executionInfo *InternalWorkflowExecutionInfo) int {
190+
if executionInfo == nil {
191+
return 0
192+
}
193+
185194
size := len(executionInfo.WorkflowID)
186195
size += len(executionInfo.TaskQueue)
187196
size += len(executionInfo.WorkflowTypeName)
@@ -191,6 +200,10 @@ func computeExecutionInfoSize(executionInfo *InternalWorkflowExecutionInfo) int
191200
}
192201

193202
func computeActivityInfoSize(ai *persistenceblobs.ActivityInfo) int {
203+
if ai == nil {
204+
return 0
205+
}
206+
194207
size := len(ai.ActivityId)
195208
if ai.ScheduledEvent != nil {
196209
size += ai.ScheduledEvent.Size()
@@ -206,12 +219,19 @@ func computeActivityInfoSize(ai *persistenceblobs.ActivityInfo) int {
206219
}
207220

208221
func computeTimerInfoSize(ti *persistenceblobs.TimerInfo) int {
222+
if ti == nil {
223+
return 0
224+
}
225+
209226
size := len(ti.GetTimerId())
210227

211228
return size
212229
}
213230

214231
func computeChildInfoSize(ci *persistenceblobs.ChildExecutionInfo) int {
232+
if ci == nil {
233+
return 0
234+
}
215235
size := 0
216236
if ci.InitiatedEvent != nil {
217237
size += ci.InitiatedEvent.Size()
@@ -223,6 +243,10 @@ func computeChildInfoSize(ci *persistenceblobs.ChildExecutionInfo) int {
223243
}
224244

225245
func computeSignalInfoSize(si *persistenceblobs.SignalInfo) int {
246+
if si == nil {
247+
return 0
248+
}
249+
226250
size := len(si.Name)
227251
size += si.GetInput().Size()
228252
size += len(si.Control)

0 commit comments

Comments
 (0)