Skip to content

32-bit archs error: Python int too large to convert to C ssize_t #2036

Closed

Description

@strophy

PyAV 16.0.1 test_opaque() fails for me on 32 bit archs including x86, armhf and armv7 under Python 3.12.12 and Cython 3.1.6 with:

=================================== FAILURES ===================================
_________________________________ test_opaque __________________________________

    def test_opaque() -> None:
        frame = VideoFrame(640, 480, "rgb24")
>       frame.opaque = 3
        ^^^^^^^^^^^^

../tests/test_videoframe.py:129: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
av/frame.py:200: in av.frame.Frame.opaque.__set__
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   OverflowError: Python int too large to convert to C ssize_t

av/opaque.pyx:18: OverflowError
=========================== short test summary info ============================
FAILED ../tests/test_videoframe.py::test_opaque - OverflowError: Python int too large to convert to C ssize_t
================== 1 failed, 298 passed, 11 skipped in 30.75s ==================

id() returns an unsigned value, but intptr_t is signed, leading to potential overflow. Patching like this fixes the issue for me:

diff --git a/av/opaque.pyx b/av/opaque.pyx
index 0c2a450..d852a41 100644
--- a/av/opaque.pyx
+++ b/av/opaque.pyx
@@ -1,5 +1,5 @@
 cimport libav as lib
-from libc.stdint cimport intptr_t, uint8_t
+from libc.stdint cimport uintptr_t, uint8_t
 from libc.string cimport memcpy
 
 
@@ -15,18 +15,18 @@ cdef class OpaqueContainer:
 
     cdef lib.AVBufferRef *add(self, object v):
         # Use object's memory address as key
-        cdef intptr_t key = id(v)
+        cdef uintptr_t key = id(v)
         self._objects[key] = v
 
-        cdef uint8_t *data = <uint8_t *>lib.av_malloc(sizeof(intptr_t))
+        cdef uint8_t *data = <uint8_t *>lib.av_malloc(sizeof(uintptr_t))
         if data == NULL:
             raise MemoryError("Failed to allocate memory for key")
 
-        memcpy(data, &key, sizeof(intptr_t))
+        memcpy(data, &key, sizeof(uintptr_t))
 
         # Create the buffer with our free callback
         cdef lib.AVBufferRef *buffer_ref = lib.av_buffer_create(
-            data, sizeof(intptr_t), key_free, NULL, 0
+            data, sizeof(uintptr_t), key_free, NULL, 0
         )
 
         if buffer_ref == NULL:
@@ -35,11 +35,11 @@ cdef class OpaqueContainer:
         return buffer_ref
 
     cdef object get(self, char *name):
-        cdef intptr_t key = (<intptr_t *>name)[0]
+        cdef uintptr_t key = (<uintptr_t *>name)[0]
         return self._objects.get(key)
 
     cdef object pop(self, char *name):
-        cdef intptr_t key = (<intptr_t *>name)[0]
+        cdef uintptr_t key = (<uintptr_t *>name)[0]
         return self._objects.pop(key, None)

Activity

  1. added 3 commits that reference this issue on Dec 17, 2025
    69c4a46
    70df1c1
    417f272
  2. added a commit that references this issue on Dec 17, 2025
    7a125bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions