MultiAudioNode: sanitize inputs

Change-Id: Ida5d74b88ec06daf738fd8b98c29737ed87c7cae
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3491
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Adrien Destugues 2021-03-16 20:54:35 +01:00 committed by Adrien Destugues
parent 572e0095c2
commit a77684c96a

View File

@ -210,6 +210,11 @@ MultiAudioNode::MultiAudioNode(BMediaAddOn* addon, const char* name,
// measured in Hertz
fOutputPreferredFormat.u.raw_audio.byte_order = B_MEDIA_HOST_ENDIAN;
if (fOutputPreferredFormat.u.raw_audio.format == 0) {
fInitStatus = B_BAD_VALUE;
return;
}
// we'll use the consumer's preferred buffer size, if any
fOutputPreferredFormat.u.raw_audio.buffer_size
= fDevice->BufferList().return_playback_buffer_size
@ -230,6 +235,11 @@ MultiAudioNode::MultiAudioNode(BMediaAddOn* addon, const char* name,
// measured in Hertz
fInputPreferredFormat.u.raw_audio.byte_order = B_MEDIA_HOST_ENDIAN;
if (fInputPreferredFormat.u.raw_audio.format == 0) {
fInitStatus = B_BAD_VALUE;
return;
}
// we'll use the consumer's preferred buffer size, if any
fInputPreferredFormat.u.raw_audio.buffer_size
= fDevice->BufferList().return_record_buffer_size
@ -722,6 +732,12 @@ MultiAudioNode::Connected(const media_source& producer,
return B_MEDIA_BAD_DESTINATION;
}
if (with_format.u.raw_audio.frame_rate <= 0
|| with_format.u.raw_audio.channel_count <= 0
|| ((with_format.u.raw_audio.format
& media_raw_audio_format::B_AUDIO_SIZE_MASK) == 0))
return B_BAD_VALUE;
_UpdateInternalLatency(with_format);
// record the agreed upon values
@ -2322,6 +2338,9 @@ MultiAudioNode::_SetNodeInputFrameRate(float frameRate)
if (error != B_OK)
return error;
if (frameRate <= 0)
return B_BAD_VALUE;
// it went fine -- update all formats
fOutputPreferredFormat.u.raw_audio.frame_rate = frameRate;
fOutputPreferredFormat.u.raw_audio.buffer_size
@ -2374,6 +2393,12 @@ MultiAudioNode::_SetNodeOutputFrameRate(float frameRate)
if (error != B_OK)
return error;
if (frameRate <= 0
|| fInputPreferredFormat.u.raw_audio.channel_count <= 0
|| ((fInputPreferredFormat.u.raw_audio.format
& media_raw_audio_format::B_AUDIO_SIZE_MASK) == 0))
return B_BAD_VALUE;
// it went fine -- update all formats
fInputPreferredFormat.u.raw_audio.frame_rate = frameRate;
fInputPreferredFormat.u.raw_audio.buffer_size