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