Commit a018405e authored by Stefan Westerfeld's avatar Stefan Westerfeld

Add error handling if compute_frame_ffts runs out of space.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 8e0cec5b
...@@ -307,10 +307,12 @@ gen_mix_entries (int block) ...@@ -307,10 +307,12 @@ gen_mix_entries (int block)
vector<vector<complex<float>>> vector<vector<complex<float>>>
compute_frame_ffts (const WavData& wav_data, size_t start_index, size_t frame_count) compute_frame_ffts (const WavData& wav_data, size_t start_index, size_t frame_count)
{ {
assert (wav_data.n_values() >= (start_index + frame_count * Params::frame_size) * wav_data.n_channels());
vector<vector<complex<float>>> fft_out; vector<vector<complex<float>>> fft_out;
/* if there is not enough space for frame_count values, return an error (empty vector) */
if (wav_data.n_values() < (start_index + frame_count * Params::frame_size) * wav_data.n_channels())
return fft_out;
/* generate analysis window */ /* generate analysis window */
vector<float> window (Params::frame_size); vector<float> window (Params::frame_size);
...@@ -939,9 +941,6 @@ public: ...@@ -939,9 +941,6 @@ public:
vector<vector<float>> vector<vector<float>>
sync_fft (const WavData& wav_data, size_t index, size_t count) sync_fft (const WavData& wav_data, size_t index, size_t count)
{ {
if (wav_data.n_values() < (index + count * Params::frame_size) * wav_data.n_channels())
return {};
/* computing db-magnitude is expensive, so we better do it here */ /* computing db-magnitude is expensive, so we better do it here */
vector<vector<float>> fft_out_db; vector<vector<float>> fft_out_db;
for (const vector<complex<float>>& spect : compute_frame_ffts (wav_data, index, count)) for (const vector<complex<float>>& spect : compute_frame_ffts (wav_data, index, count))
...@@ -991,7 +990,8 @@ decode_and_report (const WavData& wav_data, const string& orig_pattern) ...@@ -991,7 +990,8 @@ decode_and_report (const WavData& wav_data, const string& orig_pattern)
const size_t index = pos + (mark_sync_frame_count() * Params::frame_size); const size_t index = pos + (mark_sync_frame_count() * Params::frame_size);
auto fft_range_out = compute_frame_ffts (wav_data, index, count); auto fft_range_out = compute_frame_ffts (wav_data, index, count);
if (fft_range_out.size())
{
vector<vector<complex<float>>> junk; vector<vector<complex<float>>> junk;
vector<float> soft_bit_vec; vector<float> soft_bit_vec;
...@@ -1003,14 +1003,9 @@ decode_and_report (const WavData& wav_data, const string& orig_pattern) ...@@ -1003,14 +1003,9 @@ decode_and_report (const WavData& wav_data, const string& orig_pattern)
{ {
soft_bit_vec = linear_decode (fft_range_out, junk, wav_data.n_channels()); soft_bit_vec = linear_decode (fft_range_out, junk, wav_data.n_channels());
} }
if (soft_bit_vec.size() < conv_code_size (Params::payload_size))
{
fprintf (stderr, "audiowmark: input file too short to retrieve watermark\n");
fprintf (stderr, " - number of recovered raw bits %zd\n", soft_bit_vec.size());
fprintf (stderr, " - need at least %zd raw bits to get watermark\n", conv_code_size (Params::payload_size));
return 1;
}
/* truncate to the required length */ /* truncate to the required length */
assert (soft_bit_vec.size() >= conv_code_size (Params::payload_size));
soft_bit_vec.resize (conv_code_size (Params::payload_size)); soft_bit_vec.resize (conv_code_size (Params::payload_size));
vector<int> bit_vec = conv_decode_soft (randomize_bit_order (soft_bit_vec, /* encode */ false)); vector<int> bit_vec = conv_decode_soft (randomize_bit_order (soft_bit_vec, /* encode */ false));
...@@ -1031,6 +1026,7 @@ decode_and_report (const WavData& wav_data, const string& orig_pattern) ...@@ -1031,6 +1026,7 @@ decode_and_report (const WavData& wav_data, const string& orig_pattern)
} }
total_count++; total_count++;
} }
}
if (!orig_pattern.empty()) if (!orig_pattern.empty())
printf ("match_count %d %d\n", match_count, total_count); printf ("match_count %d %d\n", match_count, total_count);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment