fix: handle out-of-range in mongo when normalization is false#892
Merged
fix: handle out-of-range in mongo when normalization is false#892
Conversation
vikaxsh
reviewed
Mar 25, 2026
vikaxsh
reviewed
Mar 26, 2026
vikaxsh
approved these changes
Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
MongoDB stores dates as signed 64-bit integers (milliseconds since epoch), which supports years far beyond the standard
[0, 9999]range (e.g., negative years for BC or 10000+ for the far-future). Go'stime.Time.MarshalJSONstrictly requires years to be within[0, 9999], and encountering any value outside this range causes a fataljson: error calling MarshalJSONcrash during sync.Why this occurred only during
normalization: false:normalizationistrue, dates are processed by the shared ReformatDate utility which already includes safety bounds.normalizationisfalse, the MongoDB driver uses a lightweight filterMongoObject function. This function was directly convertingprimitive.DateTimetotime.Timewithout any guards, allowing unbounded years to hit the JSON marshaler.The Fix:
Added a safety clamp in drivers/mongodb/internal/mon.go to ensure consistent date handling:
1970-01-01 00:00:00 UTC. To keep data consistent as normalization true will make year <1 as epoch start.9999while preserving the month, day, and time components.Fixes # (issue)
Type of change
How Has This Been Tested?
Verified by injecting records with extreme dates into a local MongoDB instance and running the sync command:
-1(Date offset-62167219200001ms).0000(Date offset-62167219200000ms).10000(Date offset253402300800000ms).Both
normalization: trueandnormalization: falsemodes were tested to ensure the sync command completes without any errorScreenshots or Recordings
N/A
Documentation
Related PR's (If Any):
N/A