Fix potential segfault in Song::decode

This commit is contained in:
Polochon-street 2021-06-14 21:02:30 +02:00
parent 3236baacc6
commit f871d24c54

View file

@ -510,6 +510,7 @@ fn resample_frame(
) -> Result<Vec<f32>, BlissError> { ) -> Result<Vec<f32>, BlissError> {
let mut resampled = ffmpeg::frame::Audio::empty(); let mut resampled = ffmpeg::frame::Audio::empty();
for decoded in rx.iter() { for decoded in rx.iter() {
resampled = ffmpeg::frame::Audio::empty();
resample_context resample_context
.run(&decoded, &mut resampled) .run(&decoded, &mut resampled)
.map_err(|e| { .map_err(|e| {
@ -517,6 +518,8 @@ fn resample_frame(
})?; })?;
push_to_sample_array(&resampled, &mut sample_array); push_to_sample_array(&resampled, &mut sample_array);
} }
// TODO when ffmpeg-next will be active again: shouldn't we allocate
// `resampled` again?
loop { loop {
match resample_context.flush(&mut resampled).map_err(|e| { match resample_context.flush(&mut resampled).map_err(|e| {
BlissError::DecodingError(format!("while trying to resample song: {:?}", e)) BlissError::DecodingError(format!("while trying to resample song: {:?}", e))