Skip to content

Commit

Permalink
alsa: remove asserts based on maxChans (#729)
Browse files Browse the repository at this point in the history
Return an error if outside reasonable range.

Fixes #594
  • Loading branch information
philburk committed Sep 20, 2022
1 parent 8b6d16f commit b3f637f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/hostapi/alsa/pa_linux_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,8 @@ static PaError GropeDevice( snd_pcm_t* pcm, int isPlug, StreamDirection mode, in
PaError result = paNoError;
snd_pcm_hw_params_t *hwParams;
snd_pcm_uframes_t alsaBufferFrames, alsaPeriodFrames;
unsigned int minChans, maxChans;
unsigned int minChans = 0;
unsigned int maxChans = 0;
int* minChannels, * maxChannels;
double * defaultLowLatency, * defaultHighLatency, * defaultSampleRate =
&devInfo->baseDeviceInfo.defaultSampleRate;
Expand Down Expand Up @@ -901,9 +902,22 @@ static PaError GropeDevice( snd_pcm_t* pcm, int isPlug, StreamDirection mode, in

ENSURE_( alsa_snd_pcm_hw_params_get_channels_min( hwParams, &minChans ), paUnanticipatedHostError );
ENSURE_( alsa_snd_pcm_hw_params_get_channels_max( hwParams, &maxChans ), paUnanticipatedHostError );
assert( maxChans <= INT_MAX );
assert( maxChans > 0 ); /* Weird linking issue could cause wrong version of ALSA symbols to be called,
const unsigned int kReasonableMaxChannels = 1024;
if( maxChans > kReasonableMaxChannels )
{
PA_DEBUG(( "%s: maxChans = %u, which is unreasonably high\n", __FUNCTION__, maxChans ));
result = paUnanticipatedHostError;
goto error;
}
else if( maxChans == 0 )
{
/* Weird linking issue could cause wrong version of ALSA symbols to be called,
resulting in zeroed values */
PA_DEBUG(( "%s: minChans = %u, maxChans = %u, linking problem?\n",
__FUNCTION__, minChans, maxChans ));
result = paUnanticipatedHostError;
goto error;
}

/* XXX: Limit to sensible number (ALSA plugins accept a crazy amount of channels)? */
if( isPlug && maxChans > 128 )
Expand Down

0 comments on commit b3f637f

Please sign in to comment.