Skip to content

fix(scale): handle Number.MAX_VALUE in linear scale without overflow#12185

Open
jonathan-fulton wants to merge 1 commit intochartjs:masterfrom
jonathan-fulton:fix/12184-number-max-value-crash
Open

fix(scale): handle Number.MAX_VALUE in linear scale without overflow#12185
jonathan-fulton wants to merge 1 commit intochartjs:masterfrom
jonathan-fulton:fix/12184-number-max-value-crash

Conversation

@jonathan-fulton
Copy link

Summary

Fixes #12184

When a dataset contains Number.MAX_VALUE, the linear scale's tick generation algorithm would overflow when computing "nice" tick values, causing the chart to crash or render incorrectly.

Changes

  • Added SAFE_MAX and SAFE_MIN constants (set to Number.MAX_VALUE / 2) to prevent overflow during calculations
  • Clamp the data range to safe values before computing nice tick bounds
  • Ensure niceMin and niceMax stay within safe bounds after rounding

Testing

Added test cases for both Number.MAX_VALUE and -Number.MAX_VALUE in datasets to ensure the chart renders without crashing and produces finite scale bounds.

When a dataset contains extremely large values near Number.MAX_VALUE,
the scale's tick generation algorithm could overflow when trying to
compute 'nice' values, causing the chart to crash or the browser tab
to become unresponsive.

This fix:
- Adds SAFE_MAX/SAFE_MIN constants (half of MAX_VALUE) to prevent overflow
- Clamps data range values before tick generation calculations
- Ensures niceMin/niceMax stay within safe bounds after rounding

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to render chart when dataset includes Number.MAX_VALUE

1 participant