From: Eric Wong <normalperson@yhbt.net>
To: sox-devel@lists.sourceforge.net
Subject: Re: spectrogram segfault
Date: Tue, 29 Dec 2015 22:07:00 +0000 [thread overview]
Message-ID: <20151229220700.GA14049@dcvr.yhbt.net> (raw)
In-Reply-To: <20150101202336.GB17144@www.stare.cz>
Jan Stary <hans@stare.cz> wrote:
> It seems that if the -x size of the spectrogram is bigger
> than the number of actual samples (1000 in the example),
> or samples/second, SoX segfaults instead of rejecting that option
> (say, limiting the number to the number of samples available).
Thanks. I think ensuring p->block_steps is always >= 1
seems acceptable; but maybe there's a better way to fix this.
------------------------8<-------------------------
Subject: [PATCH] spectrogram: fix segfault when requested size exceeds length
Thanks to a bug report by Jan Stary:
ref: http://mid.gmane.org/20150101202336.GB17144@www.stare.cz
Tested with the following Perl script based on Jan's bug report.
-------------------- spectrogram.t ----------------
use strict;
use Test::More 0.88; # 0.88+ for done_testing
use File::Temp qw/tempdir/;
my $tmpdir = tempdir('sox-spectrogram.XXXXXXXX', CLEANUP => 1);
chdir($tmpdir) or die "failed to chdir: $!\n";
END { chdir('/') }; # allow $tmpdir removal when test completes
sub cmd_ok {
my ($msg, @cmd) = @_;
is(system(@cmd), 0, $msg);
}
cmd_ok('create temporary test file',
qw(sox -c 1 -b 16 -r 1000 -n file.wav synth 1 sin 440 gain -3));
cmd_ok('create PNG with default',
qw(sox file.wav -n spectrogram));
cmd_ok('create PNG with exact -x size',
qw(sox file.wav -n spectrogram -o b.png));
cmd_ok('create PNG with larger -x size (should not SEGV)',
qw(sox file.wav -n spectrogram -x 1001 -o c.png));
cmd_ok('create PNG with exact -X size',
qw(sox file.wav -n spectrogram -X 1000 -o d.png));
cmd_ok('create PNG with larger -X size (should not SEGV)',
qw(sox file.wav -n spectrogram -X 1001 -o e.png));
done_testing();
---
src/spectrogram.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/spectrogram.c b/src/spectrogram.c
index afb0b0e..5a2115f 100644
--- a/src/spectrogram.c
+++ b/src/spectrogram.c
@@ -275,6 +275,8 @@ static int start(sox_effect_t * effp)
lsx_debug("window_density=%g", actual / p->dft_size);
p->step_size = (p->slack_overlap? sqrt(actual * p->dft_size) : actual) + .5;
p->block_steps = effp->in_signal.rate / pixels_per_sec;
+ if (p->block_steps == 0)
+ p->block_steps = 1;
p->step_size = p->block_steps / ceil((double)p->block_steps / p->step_size) +.5;
p->block_steps = floor((double)p->block_steps / p->step_size +.5);
p->block_norm = 1. / p->block_steps;
--
EW
------------------------------------------------------------------------------
prev parent reply other threads:[~2015-12-29 22:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-01 20:23 spectrogram segfault Jan Stary
2015-01-22 8:48 ` Pander
2015-12-29 22:07 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.sourceforge.net/lists/listinfo/sox-devel
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151229220700.GA14049@dcvr.yhbt.net \
--to=sox-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/sox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).