Skip to content

mixer: chan_play dereferences channeldata[-1] when Mix_PlayChannelTimed/Mix_FadeInChannelTimed returns -1 #3798

Description

@coderabbitai

Bug Report

In src_c/mixer.c, the chan_play function does not check whether channelnum is -1 after calling Mix_PlayChannelTimed or Mix_FadeInChannelTimed before indexing into channeldata. If either SDL mixer call fails and returns -1, the subsequent code dereferences channeldata[-1], which is out-of-bounds and can corrupt memory.

Affected code

src_c/mixer.cchan_play function, around the block:

Py_XDECREF(channeldata[channelnum].sound);
Py_XDECREF(channeldata[channelnum].queue);
channeldata[channelnum].sound = Py_NewRef(sound);
channeldata[channelnum].queue = NULL;

A guard checking channelnum != -1 (raising an SDL error when -1) is missing here, similar to the guard already present in pgSound_Play.

References

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions