Double free in SBE hash table spill

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Critical - P2
    • 8.3.0-rc0, 8.0.20, 7.0.31, 8.2.6
    • Affects Version/s: 8.2.2, 8.0.16
    • Component/s: None
    • None
    • Query Execution
    • Fully Compatible
    • ALL
    • v8.2, v8.0, v7.0
    • QE 2026-02-16
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The problem is caused by the SBE lookup hash table under specific conditions.
      The query to trigger it can be just a simple lookup:

      db.local.aggregate({$lookup: {from: 'foreign', localField: 'k', foreignField: 'k', as: 'out'}}) 

      The conditions to trigger the bug are:

      1. $lookup must use SBE
      2. SBE must choose a hash join algorithm
      3. The hash table must be more than 100 MB to cause spilling
      4. Adding an already existing key to the hash table is what must cause the spilling
      5. The triggering hash table key must be stored in a heap memory. For example: object, array, large string

      Under these circumstances, the unnecessary “key” variable will wrongly assume ownership of tagKeyView / valKeyView. This leads to a double-free of the same value: when the “key” variable leaves the scope and whenever the keyAccessor releases its value.

            Assignee:
            Ivan Fefer
            Reporter:
            Brian Welch
            Votes:
            0 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: