Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-5056

EJSON.parse fails to parse canonical EJSON Dates when useBigInt64=true

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • bson-5.0.1
    • Affects Version/s: bson-5.0.0, 5.0.1
    • Component/s: BSON
    • Labels:
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Use Case

      As a js-bson Engineer
      I want to ensure that EJSON.parse handles parsing dates from bigints correctly

      Since BSON support was added to js-bson, EJSON.parse does not correctly deserialize
      Canonical EJSON date values which were created with EJSON.stringify when useBigInt64=true.

      Unknowns

      • The logic (listed below) makes this kind of bug easy to run into. Should we throw
        an error if we fail all of the typechecks seeing as this would be invalid EJSON by definition?
        (cite spec)
      • The existence of this bug may also imply that there are other instances of the codebase that have bugs like this elsewhere, for example in the code to parse a timestamp from cEJSON
      • Do we have a bug in how we construct EJSON using bigints?
      if (value.$date != null) {
          const d = value.$date;
          const date = new Date();
      
          if (options.legacy) {
            if (typeof d === 'number') date.setTime(d);
            else if (typeof d === 'string') date.setTime(Date.parse(d));
          } else {
            if (typeof d === 'string') date.setTime(Date.parse(d));
            else if (Long.isLong(d)) date.setTime(d.toNumber());
            else if (typeof d === 'number' && options.relaxed) date.setTime(d);
          }
          return date;
        }
      

      Acceptance Criteria

      Implementation Requirements

      • Investigate and report findings on other instances of bugs concerning the usage of bigints in the bson codebase
      • Decide on whether or not we should throw error when deserializing invalid EJSON date
      • Verify whether or not this happens with the other BSON types and resolve

      Testing Requirements

      • Write tests that check that EJSON dates are interpreted correctly when its nested $numberLong is converted to a bigint

            Assignee:
            warren.james@mongodb.com Warren James
            Reporter:
            warren.james@mongodb.com Warren James
            Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: