Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pcma decode crash #461

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/media_codecs/src/pcma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

impl AudioDecoder for PcmaDecoder {
fn decode(&mut self, in_buf: &[u8], out_buf: &mut [i16]) -> Option<usize> {
if in_buf.len() != 160 {
return None;
}

Check warning on line 21 in packages/media_codecs/src/pcma.rs

View check run for this annotation

Codecov / codecov/patch

packages/media_codecs/src/pcma.rs#L19-L21

Added lines #L19 - L21 were not covered by tests
decode_pcma(in_buf, &mut self.tmp_buf[0..in_buf.len()]);
// upsample to 48k
self.resample.resample(&self.tmp_buf[..in_buf.len()], out_buf)
Expand All @@ -38,6 +41,9 @@

impl AudioEncodder for PcmaEncoder {
fn encode(&mut self, in_buf: &[i16], out_buf: &mut [u8]) -> Option<usize> {
if in_buf.len() != 960 {
return None;
}

Check warning on line 46 in packages/media_codecs/src/pcma.rs

View check run for this annotation

Codecov / codecov/patch

packages/media_codecs/src/pcma.rs#L44-L46

Added lines #L44 - L46 were not covered by tests
// downsample to 8k
let out_samples = self.resample.resample(in_buf, &mut self.tmp_buf)?;
encode_pcma(&self.tmp_buf[..out_samples], &mut out_buf[..out_samples]);
Expand Down
Loading