Skip to content

[MEDIUM] TradingChart volume NaN/Infinity passed unchecked to lightweight-charts #2321

Description

@v1ktorrr0x

Severity: Medium

Source

app/components/trade/TradingChart.tsx:741-755

Description

hasVolumeData only checks (c.volume ?? 0) > 0. If external candle data contains NaN or Infinity in the volume field (e.g., a corrupt API response), the value passes directly into volumeSeries.setData():

volumeSeries.setData(formatted.map((c) => ({
  time: c.time,
  value: c.volume ?? 0,  // NaN/Infinity passes through unchecked
  color: '...',
})));

Some versions of lightweight-charts throw synchronously when receiving NaN/Infinity data, crashing the React tree.

Fix

Add Number.isFinite guard:

value: Number.isFinite(c.volume) ? c.volume : 0,

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions