Skip to content

Commit eadb1b6

Browse files
theomonnomsamwell
andauthored
fix SoxrResampler flush segv (#678)
* Fix: prevent crash and ensure output buffer size in SoxResampler::flush() * change: linux release add debug info * Update resampler.rs * Update ffi-builds.yml --------- Co-authored-by: samwell <sam@funcity.org>
1 parent 2d47d16 commit eadb1b6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

livekit-ffi/src/server/resampler.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ impl SoxResampler {
7171
return Err(error_msg.to_string_lossy().to_string());
7272
}
7373

74-
Ok(Self { soxr_ptr, out_buf: Vec::new(), input_rate, output_rate, num_channels })
74+
Ok(Self {
75+
soxr_ptr,
76+
out_buf: Vec::with_capacity(output_rate as usize / 100), // ensure valid memory ptr
77+
input_rate,
78+
output_rate,
79+
num_channels,
80+
})
7581
}
7682

7783
pub fn push(&mut self, input: &[i16]) -> Result<&[i16], String> {
@@ -134,7 +140,8 @@ impl SoxResampler {
134140
return Err(error_msg.to_string_lossy().to_string());
135141
}
136142

137-
Ok(&self.out_buf[..odone])
143+
let output_samples = odone * self.num_channels as usize;
144+
Ok(&self.out_buf[..output_samples])
138145
}
139146
}
140147

0 commit comments

Comments
 (0)