__random_leaf_disk crashes with SIGFPE on a disk page with zero entries

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Btree
    • Storage Engines - Foundations
    • 476.569
    • None
    • None

      Problem

      __random_leaf_disk crashes with SIGFPE (divide by zero) when it encounters a disk page with zero entries. The crash is at bt_random.c:241:

      slot = __wt_random(&cbt->rnd) % entries;
      

      Root Cause

      _random_leaf calls random_leaf_disk when it finds an unmodified page from disk (page->dsk != NULL && page->modify == NULL), regardless of whether page->entries is zero. _random_leaf_disk reads entries from page->entries but does not guard against a zero value before the modulo.

      An empty row-store leaf page on disk satisfies the dsk != NULL && modify == NULL condition. When the tree walk in _wt_btcur_next_random lands on such a page, control reaches _random_leaf_disk with entries == 0 and the modulo faults.

      The fix is to return early from __random_leaf_disk when entries == 0, leaving validp false so the caller falls through to the cursor-walk path, which already handles empty trees correctly.

            Assignee:
            [DO NOT USE] Backlog - Storage Engines Team
            Reporter:
            Jie Chen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: