-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
None
Detailed steps to reproduce the problem?
See SECBUG-6768. It links the two crash documents, the repro script, and the
AddressSanitizer reports. bson.decode() reads 4 to 8 bytes past the end of
the input buffer when it decodes an array whose last element is truncated.
Impact
The over-read value is discarded and decode() raises InvalidBSON, so
no leak is demonstrated. Under hardened allocators the read aborts the
process. Out-of-bounds read, CWE-125.
Root cause
The array element loop in bson/_cbsonmodule.c bounds keys and values by
the outer document's remaining length instead of the sub-document's own
remaining bytes. Details in SECBUG-6768.
Affected versions
Every release that ships the C extension, from pymongo 1.9 up to the
fix in pymongo 4.20.2 (1.9 < 4.20.2). The pure-Python decoder is not affected.
The fix
Prepared on the PYTHON-6169 branch and to land in its own change first. The
array element loop bounds keys and values by the sub-document's remaining
bytes and the two crash documents are committed as reproducers. This ticket
blocks PYTHON-6169, the native ASan fuzzing pipeline. The pipeline found this
bug on its first run and its fuzz-native task can only run green once the
fix lands.
Definition of done
The fix lands in its own change. The reproducers replay cleanly through both
implementations. The SECBUG-6768 triage outcome is incorporated and
PYTHON-6169 is then unblocked.
Security Vulnerabilities
Handled per the Security Triage Guide for BSON and EJSON and tracked as
SECBUG-6768 (Private Bug).