You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Potential Integer Overflow in cpSpaceAddCachedArbiter #300
We are researchers from the University of Athens, working on cross-language analysis of Python packages with C/C++ native extensions.
Problem
We found an issue in the pymunk package. The function cpSpaceAddCachedArbiter() [1] does not check arb->count [2] before copying them.
If arb->count is large, multiplying it by the size of the contact structure [3] can overflow, producing a smaller value. This causes memcpy() [3] to write past the allocated memory, which can lead to crashes or segmentation faults.
Steps to Reproduce
Open a terminal and run the following Python script:
When I run you repro-code I do get a crash, but not a segfault.
Aborting due to Chipmunk error:
Internal Error: Contact buffer overflow!
Failed condition: count <= CP_MAX_CONTACTS_PER_ARBITER
Source: Munk2D/src/cpSpaceStep.c:177
Which is expected since there cant be more than 2 contacts for one arbiter. I guess it could segfault if you are very low on memory? On the other hand, this is an internal function in Pymunk, only used when unpickling a Space, so it would have to be quite extreme for it to fail.
(I havent really had the time to think about this and the other issue you opened)
Can I ask, how do analyze the code? Some automated way I assume?
(Sorry for somewhat late reply, I have been away abroad during the holidays).
Activity
viblo commentedon Jan 19, 2026
Thanks for the report!
When I run you repro-code I do get a crash, but not a segfault.
Which is expected since there cant be more than 2 contacts for one arbiter. I guess it could segfault if you are very low on memory? On the other hand, this is an internal function in Pymunk, only used when unpickling a Space, so it would have to be quite extreme for it to fail.
(I havent really had the time to think about this and the other issue you opened)
Can I ask, how do analyze the code? Some automated way I assume?
(Sorry for somewhat late reply, I have been away abroad during the holidays).