From 15c0340eafd782943239f5cf8d85ef8e74a88f5e Mon Sep 17 00:00:00 2001 From: Ali <> Date: Fri, 16 Jul 2021 00:22:30 +0200 Subject: [PATCH] Disallow variable number of channels --- submodules/FFMpegBinding/Sources/FFMpegSWResample.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/submodules/FFMpegBinding/Sources/FFMpegSWResample.m b/submodules/FFMpegBinding/Sources/FFMpegSWResample.m index fbecf0555b..16c2a888dc 100644 --- a/submodules/FFMpegBinding/Sources/FFMpegSWResample.m +++ b/submodules/FFMpegBinding/Sources/FFMpegSWResample.m @@ -6,6 +6,7 @@ #import "libswresample/swresample.h" @interface FFMpegSWResample () { + int _sourceChannelCount; SwrContext *_context; NSUInteger _ratio; NSInteger _destinationChannelCount; @@ -21,6 +22,7 @@ - (instancetype)initWithSourceChannelCount:(NSInteger)sourceChannelCount sourceSampleRate:(NSInteger)sourceSampleRate sourceSampleFormat:(enum FFMpegAVSampleFormat)sourceSampleFormat destinationChannelCount:(NSInteger)destinationChannelCount destinationSampleRate:(NSInteger)destinationSampleRate destinationSampleFormat:(enum FFMpegAVSampleFormat)destinationSampleFormat { self = [super init]; if (self != nil) { + _sourceChannelCount = sourceChannelCount; _destinationChannelCount = destinationChannelCount; _destinationSampleFormat = destinationSampleFormat; _context = swr_alloc_set_opts(NULL, @@ -47,6 +49,12 @@ - (NSData * _Nullable)resample:(FFMpegAVFrame *)frame { AVFrame *frameImpl = (AVFrame *)[frame impl]; + + int numChannels = frameImpl->channels; + if (numChannels != _sourceChannelCount) { + return nil; + } + int bufSize = av_samples_get_buffer_size(NULL, (int)_destinationChannelCount, frameImpl->nb_samples * (int)_ratio,