Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-68309

Investigate for unsafe narrowing conversions

    XMLWordPrintable

Details

    • Task
    • Status: Closed
    • Major - P3
    • Resolution: Done
    • None
    • None
    • None
    • None
    • Execution Team 2022-08-08, Execution Team 2022-08-22

    Description

      BSONElement methods numberLong and  numberInt are used in dozens of places in the codebase, but it's not clear a priori which uses might actually be problematic. If used on a NumberDouble with a NaN value, they simply cast to the desired type, and this can result in undefined behavior that differs depending on the platform. If we know that the type of element is the matching type, then we can safely use these methods to extract it. In many cases, this holds, either where we've already checked the type explicitly, or we know that we constructed this value to be a specific type because it's for internal use and we have a schema for these documents. But in some cases, we probably are just using these methods mistakenly to deal with input of unknown type, when we should be checking the type explicitly.

      We are already aware of some issues (e.g. SERVER-68359), but more problematic uses could still be lingering, and we should audit the codebase.

      Attachments

        Issue Links

          Activity

            People

              dan.larkin-york@mongodb.com Dan Larkin-York
              dan.larkin-york@mongodb.com Dan Larkin-York
              Votes:
              0 Vote for this issue
              Watchers:
              15 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: