PYTHON-5996ClosedFixed

Harden bson buffer size guard against signed-overflow UB on >2GiB encode

h3. Detailed steps to reproduce the problem? _Include full traceback, if possible_ Encoding a single document whose values' cumulative encoded size exceeds INT_MAX (about 2 GiB) overflows the running buffer position in {{buffer_assure_space}} ({{bson/buffer.c}}). The overflow guard {{new_size < buffer->position}} depends on signed-overflow wraparound, which is undefined behavior. Compilers in the LLVM family (clang, and clang-based toolchains such as {{zig cc}} and Intel ICX) optimize the c

Affected Versions
Versions known to exhibit this issue

No affected versions recorded.

Fixed Versions
Versions that include the fix
4.18.2
Components
Server components related to this issue
Security
Labels
Tags and classification

No labels assigned.