Skip to content

fix(utils): guard adjustTime against non-finite deltas (freeze + NaN:NaN)#3584

Open
arham766 wants to merge 1 commit into
facebook:mainfrom
arham766:fix/adjust-time-nonfinite
Open

fix(utils): guard adjustTime against non-finite deltas (freeze + NaN:NaN)#3584
arham766 wants to merge 1 commit into
facebook:mainfrom
arham766:fix/adjust-time-nonfinite

Conversation

@arham766

@arham766 arham766 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3583.

adjustTime's wrap-around loop never terminates for deltaMinutes = -Infinity (-Infinity + 1440 is still -Infinity) — a pure CPU spin that freezes the tab — and NaN skips the loop and flows through formatISOTime as the corrupt string "NaN:NaN", which isTimeInRange doesn't reject, so DateTimeInput can commit it into consumer form state. Both are reachable from the public timeIncrement prop via the ArrowUp/ArrowDown handler whenever a consumer computes the step (60 * undefined → NaN, division by zero → ±Infinity).

The fix: non-finite deltas return the input time unchanged, and the negative wrap-around becomes a double-modulo (((m % 1440) + 1440) % 1440) — O(1) for huge finite negatives too.

Test plan

  • New tests: -Infinity/Infinity/NaN all return the input unchanged (the -Infinity case previously hung — verified via subprocess kill at 8s pre-fix); huge negative finite deltas wrap correctly in constant time
  • timeParser + TimeInput + DateTimeInput suites: 116 tests green
  • typecheck + eslint clean

@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown

@arham766 is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 4, 2026
@arham766 arham766 force-pushed the fix/adjust-time-nonfinite branch from 630a129 to 2a86b37 Compare July 4, 2026 20:53
deltaMinutes of -Infinity spun the wrap-around while-loop forever (a
pure CPU spin that freezes the tab), and NaN skipped the loop and
flowed through formatISOTime as the corrupt string "NaN:NaN", which
isTimeInRange does not reject. Both are reachable from DateTimeInput's
public timeIncrement prop via the ArrowUp/Down handler when a consumer
computes the step (undefined arithmetic or division by zero).

Return the input unchanged for non-finite deltas, and replace the
negative wrap-around loop with a double-modulo so huge finite negative
deltas also wrap in constant time.

Fixes facebook#3583
@arham766 arham766 force-pushed the fix/adjust-time-nonfinite branch from 2a86b37 to f9c4a69 Compare July 4, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] adjustTime freezes the tab on a non-finite delta (-Infinity) and emits 'NaN:NaN' on NaN — reachable from DateTimeInput timeIncrement

1 participant