fix: message-parser timestamps overflow for dates from 2038 - #41752
fix: message-parser timestamps overflow for dates from 2038#41752Osamaali313 wants to merge 1 commit into
Conversation
`<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.
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
🦋 Changeset detectedLatest commit: 371a726 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
WalkthroughThe message parser now converts Unix timestamps with ChangesTimestamp overflow correction
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/message-parser/tests/timestamp.test.ts (1)
58-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd regression coverage for
timestampFromHours.This case uses an ISO-8601 input, so it exercises
timestampFromIsoTime. It does not executetimestampFromHours, changed at Line 366 inpackages/message-parser/src/utils.ts. Add an hour-only timestamp case with the clock fixed after2038-01-19T03:14:07Z.The grammar routes hour-only timestamps through
timestampFromHoursat Lines 133-137 inpackages/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
📒 Files selected for processing (3)
.changeset/fix-message-parser-timestamp-overflow.mdpackages/message-parser/src/utils.tspackages/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.tspackages/message-parser/src/utils.ts
packages/**
📄 CodeRabbit inference engine (CLAUDE.md)
Shared libraries belong in
packages/, while other services belong inapps/andee/.
Files:
packages/message-parser/tests/timestamp.test.tspackages/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.tspackages/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.tspackages/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.tspackages/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. |
There was a problem hiding this comment.
📐 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.
| 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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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>
| 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. |
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:| 0performs aToInt32coercion, so any value past2^31wraps negative. For<t:2040-01-01T00:00:00.000+00:00>the correct epoch is2208988800, but| 0yields-2085978496, which the renderer (gazzodownTimestamp) turns into a 1903 date. A 4-digit year reaches this via the defaultTimestampRuleschain 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.floorinstead of| 0intimestampFromIsoTimeand the siblingtimestampFromHours. The epoch values are non-negative, so for every in-range dateMath.floorand 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 case2040-01-01...now yields2208988800instead of-2085978496.Types of changes
Checklist
packages/message-parser/tests/timestamp.test.ts, a case past the 2038 boundary)@rocket.chat/message-parserpatch)Summary by CodeRabbit
Bug Fixes
Tests