From 25770647e64273de2b87a57b8599aaf6ae5f7a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=AF=E6=8C=AF=E5=87=AF?= Date: Mon, 3 Nov 2025 22:15:55 +0800 Subject: [PATCH] fix: add bounds check to getColumnWidth function --- src/VirtualTable/VirtualCell.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/VirtualTable/VirtualCell.tsx b/src/VirtualTable/VirtualCell.tsx index ebcfff4ad..0b2d2d896 100644 --- a/src/VirtualTable/VirtualCell.tsx +++ b/src/VirtualTable/VirtualCell.tsx @@ -31,9 +31,15 @@ export interface VirtualCellProps { * Return the width of the column by `colSpan`. * When `colSpan` is `0` will be trade as `1`. */ -export function getColumnWidth(colIndex: number, colSpan: number, columnsOffset: number[]) { +export function getColumnWidth(colIndex: number, colSpan: number, columnsOffset: number[]): number { const mergedColSpan = colSpan || 1; - return columnsOffset[colIndex + mergedColSpan] - (columnsOffset[colIndex] || 0); + + const startIndex = Math.max(colIndex, 0); + const endIndex = Math.min(startIndex + mergedColSpan, columnsOffset.length - 1); + + const startOffset = columnsOffset[startIndex] || 0; + const endOffset = columnsOffset[endIndex] || startOffset; + return Math.max(endOffset - startOffset, 0); } const VirtualCell = (props: VirtualCellProps) => {