fix(core): Integer overflow in insights runtime calculation (#18122)

Co-authored-by: Shi Nguyễn <prettycode2022@Shis-MacBook-Pro.local>
This commit is contained in:
Shi Nguyễn
2025-08-22 18:05:04 +07:00
committed by GitHub
parent 8b4e8f347f
commit c7678311b3

View File

@@ -42,6 +42,11 @@ const shouldSkipMode: Record<WorkflowExecuteMode, boolean> = {
manual: true,
};
const MIN_RUNTIME = 0;
// PostgreSQL INTEGER max (signed 32-bit)
const MAX_RUNTIME = 2 ** 31 - 1;
type BufferedInsight = Pick<InsightsRaw, 'type' | 'value' | 'timestamp'> & {
workflowId: string;
workflowName: string;
@@ -135,7 +140,11 @@ export class InsightsCollectionService {
// run time event
if (ctx.runData.stoppedAt) {
const value = ctx.runData.stoppedAt.getTime() - ctx.runData.startedAt.getTime();
const runtimeMs = ctx.runData.stoppedAt.getTime() - ctx.runData.startedAt.getTime();
if (runtimeMs < MIN_RUNTIME || runtimeMs > MAX_RUNTIME) {
this.logger.warn(`Invalid runtime detected: ${runtimeMs}ms, clamping to safe range`);
}
const value = Math.min(Math.max(runtimeMs, MIN_RUNTIME), MAX_RUNTIME);
this.bufferedInsights.add({
...commonWorkflowData,
type: 'runtime_ms',