Validation reports a spurious extra index entry on a numericOrdering collated index because the stored and regenerated index keys differ

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Storage Execution
    • ALL
    • Storage Execution 2026-08-17, Storage Execution 2026-08-31, Storage Execution 2026-09-14, Storage Execution 2026-09-28
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      Offline validation (mongod --validate) reports a collated index as inconsistent (one extra index entry, keysPerIndex == nrecords) for a document's own freshly-written data. Reproduces on current master by writing and validating with the same binary, so this is not storage-level data corruption.

      Root cause

      ICU's getCollationKey with numericOrdering: true writes uninitialized memory into the sort key's numeric region, and CollatorInterfaceICU::getComparisonKey copies it into the index key. The uninitialized bytes depend on the memory state at the moment of the call, so the same string yields different key bytes at different call sites and in different processes. The write path stores one value; a later regeneration (offline validate) produces another; validation sees a mismatch and reports an extra entry. The divergence is confined to the collation-transformed value of the affected field (type bits and framing are identical), and neither key is authoritative since the collated key is non-reproducible.

      Evidence: printing getComparisonKey on the affected string in three separate processes gives byte-identical output except for one 8-byte region that decodes as a little-endian heap pointer whose high bytes track ASLR.

      Trigger

      Requires both numericOrdering: true in the collation and digits in the collated string. Turning off numericOrdering or removing the digits does not touch the numeric sort-key path, and validation passes.

            Assignee:
            Shin Yee Tan
            Reporter:
            Shin Yee Tan
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: