Skip to content

Add type-check for renderer parameter in texture_init to prevent crashes #3745

@coderabbitai

Description

@coderabbitai

Summary

In src_c/render.c, the texture_init function parses the renderer argument using the generic O format specifier in PyArg_ParseTupleAndKeywords, but then immediately casts and dereferences it as a pgRendererObject * without any type validation. Passing a non-Renderer Python object will cause invalid memory access / a crash.

Suggested Fix

Use the O! format specifier with &pgRenderer_Type to enforce the type at parse time:

-    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|ippp", keywords,
-                                     &renderer, &sizeobj, &depth, &staticc,
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!O|ippp", keywords,
+                                     &pgRenderer_Type, &renderer, &sizeobj,
+                                     &depth, &staticc,
                                      &streaming, &target)) {
         return -1;
     }

References

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions