mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
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:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user