Skip to content

fix: guard timestamp formatting against NaN input (#498) - #513

Open
fuleinist wants to merge 1 commit into
airframesio:masterfrom
fuleinist:fix/timestamp-nan-guard
Open

fix: guard timestamp formatting against NaN input (#498)#513
fuleinist wants to merge 1 commit into
airframesio:masterfrom
fuleinist:fix/timestamp-nan-guard

Conversation

@fuleinist

Copy link
Copy Markdown
Contributor

Fixes #498.

Summary

DateTimeUtils.timestampToString(NaN) fell through both range checks (NaN < 86400 is false) to new Date(NaN).toISOString(), throwing RangeError: Invalid time value. Since MessageDecoder.decode() has no top-level try/catch, one malformed time field aborted the entire decode.

Repro from the issue: a Label 44 ETA message with a non-numeric timestamp field (e.g. ...1107,ABCD,0208,...) → convertHHMMSSToTod('ABCD')NaNResultFormatter.timestamp(result, NaN) → RangeError.

Fix

Two levels, mirroring the existing isNaN guards on position / altitude / flightNumber:

  1. DateTimeUtils.timestampToString returns '' for NaN instead of throwing.
  2. The timestamp-family formatters — timestamp, eta, out, off, on, in, engineStart, engineStop — return early without setting the raw field or pushing a formatted item when the input is NaN.

Note: out was not listed in #498 but has the identical pattern, so it is guarded too.

Tests

Full suite: 480 passed, 9 skipped (pre-existing). The flight_plan_utils tsc errors visible under tsc --noEmit are pre-existing on master and untouched by this change.

timestampToString(NaN) fell through to new Date(NaN).toISOString() and threw RangeError, aborting the entire MessageDecoder.decode() for any plugin feeding a malformed time field into the timestamp-family formatters (e.g. Label_44_ETA with a non-numeric timestamp field).

Guard at two levels: timestampToString returns '' for NaN, and ResultFormatter.timestamp/eta/out/off/on/in/engineStart/engineStop skip the field entirely when the input is NaN, mirroring the existing isNaN guards on position/altitude/flightNumber. Note: out was not listed in airframesio#498 but shares the exact pattern, so it is guarded too.

Tests: timestampToString NaN regression, per-method NaN guard table test, Label_44_ETA end-to-end repro from airframesio#498. Full suite 480 passed / 9 skipped (pre-existing).
Copilot AI lite review requested due to automatic review settings August 4, 2026 12:47
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@fuleinist, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cd7d96c5-3b72-4d52-9f5e-75c1edfe2b2f

📥 Commits

Reviewing files that changed from the base of the PR and between c4b61b4 and aa21637.

📒 Files selected for processing (5)
  • lib/DateTimeUtils.test.ts
  • lib/DateTimeUtils.ts
  • lib/plugins/Label_44_ETA.test.ts
  • lib/utils/result_formatter.test.ts
  • lib/utils/result_formatter.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Ready to approve

The changes directly address the reported crash path with targeted guards and include focused unit and end-to-end regression tests.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR fixes a crash where malformed/non-numeric time fields could propagate NaN into DateTimeUtils.timestampToString(), triggering new Date(NaN).toISOString()RangeError: Invalid time value and aborting MessageDecoder.decode().

Changes:

  • Add a NaN guard in DateTimeUtils.timestampToString() to return '' instead of throwing.
  • Add early-return NaN guards across the “timestamp-family” ResultFormatter methods to avoid setting raw fields or emitting formatted items when the input is NaN.
  • Add unit + end-to-end tests covering the regression (including the Label 44 ETA repro path from issue #498).
File summaries
File Description
lib/utils/result_formatter.ts Skips timestamp-related formatting entirely when the provided time value is NaN.
lib/utils/result_formatter.test.ts Adds table-driven tests ensuring timestamp-family formatters don’t throw and don’t emit output on NaN.
lib/plugins/Label_44_ETA.test.ts Adds an end-to-end repro ensuring a malformed timestamp field does not abort decoding.
lib/DateTimeUtils.ts Prevents timestampToString(NaN) from throwing by returning an empty string.
lib/DateTimeUtils.test.ts Adds tests verifying timestampToString(NaN) is non-throwing and valid TOD formatting still works.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

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.

Bug: DateTimeUtils.timestampToString(NaN) throws RangeError, aborting MessageDecoder.decode() for any non-numeric time field

2 participants