History

rate: fix crash when input and output rates are very close [bug #334]

If the rate factor is too close to 1, resampling isn't possible. Detect this and bypass the rate effect. This only happens if the output rate is within about 50 ppb of the input, so it is unlikely to occur in normal use.

Mans Rullgard committed 6 years ago

Commit 9ce4a4a1 parent c04163d1 file · +16 −1Browse files

Unified · Split

src/rate.c+16−1
@@ -337,6 +337,10 @@ static void rate_init( · 336 unmodified lines
337337 }
338338
339339 p->num_stages = shift + have_pre_stage + have_arb_stage + have_post_stage;
340+
341+ if (!p->num_stages)
342+ return;
343+
340344 p->stages = calloc(p->num_stages + 1, sizeof(*p->stages));
341345 for (i = 0; i < p->num_stages; ++i)
342346 p->stages[i].shared = shared;
@@ -496,9 +500,14 @@ static void rate_flush(rate_t * p) · 153 unmodified lines
496500
497501 static void rate_close(rate_t * p)
498502 {
499− rate_shared_t * shared = p->stages[0].shared;
503+ rate_shared_t *shared;
500504 int i;
501505
506+ if (!p->num_stages)
507+ return;
508+
509+ shared = p->stages[0].shared;
510+
502511 for (i = 0; i <= p->num_stages; ++i)
503512 fifo_delete(&p->stages[i].fifo);
504513 free(shared->dft_filter[0].coefs);
@@ -632,6 +641,12 @@ static int start(sox_effect_t * effp) · 127 unmodified lines
632641 rate_init(&p->rate, p->shared_ptr, effp->in_signal.rate/out_rate,p->bit_depth,
633642 p->phase, p->bw_0dB_pc, p->anti_aliasing_pc, p->rolloff, !p->given_0dB_pt,
634643 p->use_hi_prec_clock, p->coef_interp, p->max_coefs_size, p->noIOpt);
644+
645+ if (!p->rate.num_stages) {
646+ lsx_warn("input and output rates too close, skipping resampling");
647+ return SOX_EFF_NULL;
648+ }
649+
635650 return SOX_SUCCESS;
636651 }
637652

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t