Skip to content

fix: message-parser timestamps overflow for dates from 2038 - #41752

Open
Osamaali313 wants to merge 1 commit into
RocketChat:developfrom
Osamaali313:fix-timestamp-2038-overflow
Open

fix: message-parser timestamps overflow for dates from 2038#41752
Osamaali313 wants to merge 1 commit into
RocketChat:developfrom
Osamaali313:fix-timestamp-2038-overflow

Conversation

@Osamaali313

@Osamaali313 Osamaali313 commented Aug 11, 2026

Copy link
Copy Markdown

Proposed changes

<t:...> timestamp markup with a date on or after 2038-01-19 03:14:07 UTC renders as a wrong date (a 1903 date) instead of the real one.

In packages/message-parser/src/utils.ts, both timestamp helpers coerce the epoch seconds with | 0:

const date = (new Date(`${year}-${month}-${day}T...`).getTime() / 1000) | 0;

| 0 performs a ToInt32 coercion, so any value past 2^31 wraps negative. For <t:2040-01-01T00:00:00.000+00:00> the correct epoch is 2208988800, but | 0 yields -2085978496, which the renderer (gazzodown Timestamp) turns into a 1903 date. A 4-digit year reaches this via the default TimestampRules chain in the grammar (ISO8601Date / ISO8601DateWithoutMilliseconds), so any message with a future <t:YYYY-...> is affected — deadlines, contract dates, reminders all silently render ~15 years of future dates wrong.

Fix

Use Math.floor instead of | 0 in timestampFromIsoTime and the sibling timestampFromHours. The epoch values are non-negative, so for every in-range date Math.floor and the old truncation produce the identical result — this only removes the 32-bit overflow.

I verified in-range parity against the existing test cases (2025-07-22...1753178400, 2025-07-24T20:19:58.154...1753388398) — unchanged — and the new boundary case 2040-01-01... now yields 2208988800 instead of -2085978496.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)

Checklist

  • I have read the Contributing guidelines
  • I added a regression test (packages/message-parser/tests/timestamp.test.ts, a case past the 2038 boundary)
  • Added a changeset (@rocket.chat/message-parser patch)

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Fixed date and timestamp rendering for dates on or after January 19, 2038.
    • Prevented timestamp overflow that could produce incorrect dates for future messages.
  • Tests

    • Added coverage for timestamps from 2040 to verify accurate date conversion.

`<t:...>` timestamps parsed the epoch seconds with `(... / 1000) | 0`.
The `| 0` coerces to a signed 32-bit integer, so any date at or after
2038-01-19 03:14:07 UTC wraps to a negative value — e.g.
`<t:2040-01-01T00:00:00.000+00:00>` became -2085978496, which the
renderer shows as a 1903 date instead of 2040.

Use `Math.floor` instead of `| 0` in both `timestampFromIsoTime` and the
sibling `timestampFromHours`. For all in-range dates the result is
identical (the inputs are non-negative, so floor and truncation agree),
so this only fixes the overflow. Added a regression test past the 2038
boundary.
Copilot AI lite review requested due to automatic review settings August 11, 2026 19:45
@dionisio-bot

dionisio-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@changeset-bot

changeset-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 371a726

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@rocket.chat/message-parser Patch
@rocket.chat/gazzodown Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CLAassistant

CLAassistant commented Aug 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The message parser now converts Unix timestamps with Math.floor instead of 32-bit truncation. A regression test covers a 2040 timestamp, and a patch changeset documents the fix.

Changes

Timestamp overflow correction

Layer / File(s) Summary
Safe timestamp conversion and regression coverage
packages/message-parser/src/utils.ts, packages/message-parser/tests/timestamp.test.ts, .changeset/fix-message-parser-timestamp-overflow.md
timestampFromHours and timestampFromIsoTime now use Math.floor. The test verifies the Unix timestamp for a 2040 date. The changeset records the patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: type: bug

Suggested reviewers: ggazzo

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing message-parser timestamp overflow for dates from 2038 onward.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TIMESTAMP-2038: Request failed with status code 401

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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/message-parser/tests/timestamp.test.ts (1)

58-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression coverage for timestampFromHours.

This case uses an ISO-8601 input, so it exercises timestampFromIsoTime. It does not execute timestampFromHours, changed at Line 366 in packages/message-parser/src/utils.ts. Add an hour-only timestamp case with the clock fixed after 2038-01-19T03:14:07Z.

The grammar routes hour-only timestamps through timestampFromHours at Lines 133-137 in packages/message-parser/src/grammar.pegjs.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/message-parser/tests/timestamp.test.ts` at line 58, Add a regression
test in the timestamp test cases that uses the hour-only timestamp syntax and a
clock value after 2038-01-19T03:14:07Z, ensuring grammar parsing invokes
timestampFromHours rather than timestampFromIsoTime. Keep the expected Unix
timestamp and format marker aligned with the new hour-only input.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/fix-message-parser-timestamp-overflow.md:
- Line 5: Update the changeset wording to state that signed 32-bit overflow
begins after 2038-01-19 03:14:07 UTC, rather than implying the entire date is
affected; retain that Math.floor fixes future timestamp parsing.

---

Nitpick comments:
In `@packages/message-parser/tests/timestamp.test.ts`:
- Line 58: Add a regression test in the timestamp test cases that uses the
hour-only timestamp syntax and a clock value after 2038-01-19T03:14:07Z,
ensuring grammar parsing invokes timestampFromHours rather than
timestampFromIsoTime. Keep the expected Unix timestamp and format marker aligned
with the new hour-only input.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 566557e8-ef6e-4893-ab8d-c20b887591d2

📥 Commits

Reviewing files that changed from the base of the PR and between 15a251c and 371a726.

📒 Files selected for processing (3)
  • .changeset/fix-message-parser-timestamp-overflow.md
  • packages/message-parser/src/utils.ts
  • packages/message-parser/tests/timestamp.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/message-parser/tests/timestamp.test.ts
  • packages/message-parser/src/utils.ts
packages/**

📄 CodeRabbit inference engine (CLAUDE.md)

Shared libraries belong in packages/, while other services belong in apps/ and ee/.

Files:

  • packages/message-parser/tests/timestamp.test.ts
  • packages/message-parser/src/utils.ts
🧠 Learnings (4)
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts
  • packages/message-parser/src/utils.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts
  • packages/message-parser/src/utils.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts
  • packages/message-parser/src/utils.ts
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.

Applied to files:

  • .changeset/fix-message-parser-timestamp-overflow.md
🔇 Additional comments (2)
packages/message-parser/src/utils.ts (1)

366-366: LGTM!

Also applies to: 390-393

.changeset/fix-message-parser-timestamp-overflow.md (1)

1-3: LGTM!

'@rocket.chat/message-parser': patch
---

Fixes `<t:...>` timestamps with dates on or after 2038-01-19 rendering as a wrong (1903) date. The parser truncated the epoch seconds with `| 0`, which overflows the 32-bit signed range; it now uses `Math.floor`, so future dates parse correctly.

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Document the exact overflow boundary.

The signed 32-bit maximum remains valid at 2038-01-19T03:14:07Z. Overflow starts after that instant. Line 5 currently implies that all of January 19 is affected.

The PR objective identifies the boundary as 2038-01-19 03:14:07 UTC.

Proposed wording
-Fixes `<t:...>` timestamps with dates on or after 2038-01-19 rendering as a wrong (1903) date. The parser truncated the epoch seconds with `| 0`, which overflows the 32-bit signed range; it now uses `Math.floor`, so future dates parse correctly.
+Fixes `<t:...>` timestamps after 2038-01-19 03:14:07 UTC rendering as incorrect pre-epoch dates. The parser truncated epoch seconds with `| 0`, which overflows the 32-bit signed range; it now uses `Math.floor`, so future dates parse correctly.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Fixes `<t:...>` timestamps with dates on or after 2038-01-19 rendering as a wrong (1903) date. The parser truncated the epoch seconds with `| 0`, which overflows the 32-bit signed range; it now uses `Math.floor`, so future dates parse correctly.
Fixes `<t:...>` timestamps after 2038-01-19 03:14:07 UTC rendering as incorrect pre-epoch dates. The parser truncated epoch seconds with `| 0`, which overflows the 32-bit signed range; it now uses `Math.floor`, so future dates parse correctly.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.changeset/fix-message-parser-timestamp-overflow.md at line 5, Update the
changeset wording to state that signed 32-bit overflow begins after 2038-01-19
03:14:07 UTC, rather than implying the entire date is affected; retain that
Math.floor fixes future timestamp parsing.

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name=".changeset/fix-message-parser-timestamp-overflow.md">

<violation number="1" location=".changeset/fix-message-parser-timestamp-overflow.md:5">
P3: The changeset wording says dates "on or after 2038-01-19" are affected, but the 32-bit signed epoch overflow actually starts after 2038-01-19T03:14:07Z (values before that time are still valid). Consider tightening the wording to reference the exact boundary instant, e.g. "after 2038-01-19T03:14:07Z", to avoid implying all of Jan 19 is affected.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

'@rocket.chat/message-parser': patch
---

Fixes `<t:...>` timestamps with dates on or after 2038-01-19 rendering as a wrong (1903) date. The parser truncated the epoch seconds with `| 0`, which overflows the 32-bit signed range; it now uses `Math.floor`, so future dates parse correctly.

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.

P3: The changeset wording says dates "on or after 2038-01-19" are affected, but the 32-bit signed epoch overflow actually starts after 2038-01-19T03:14:07Z (values before that time are still valid). Consider tightening the wording to reference the exact boundary instant, e.g. "after 2038-01-19T03:14:07Z", to avoid implying all of Jan 19 is affected.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .changeset/fix-message-parser-timestamp-overflow.md, line 5:

<comment>The changeset wording says dates "on or after 2038-01-19" are affected, but the 32-bit signed epoch overflow actually starts after 2038-01-19T03:14:07Z (values before that time are still valid). Consider tightening the wording to reference the exact boundary instant, e.g. "after 2038-01-19T03:14:07Z", to avoid implying all of Jan 19 is affected.</comment>

<file context>
@@ -0,0 +1,5 @@
+'@rocket.chat/message-parser': patch
+---
+
+Fixes `<t:...>` timestamps with dates on or after 2038-01-19 rendering as a wrong (1903) date. The parser truncated the epoch seconds with `| 0`, which overflows the 32-bit signed range; it now uses `Math.floor`, so future dates parse correctly.
</file context>
Suggested change
Fixes `<t:...>` timestamps with dates on or after 2038-01-19 rendering as a wrong (1903) date. The parser truncated the epoch seconds with `| 0`, which overflows the 32-bit signed range; it now uses `Math.floor`, so future dates parse correctly.
Fixes `<t:...>` timestamps after 2038-01-19 03:14:07 UTC rendering as incorrect pre-epoch dates. The parser truncated epoch seconds with `| 0`, which overflows the 32-bit signed range; it now uses `Math.floor`, so future dates parse correctly.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants