1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 01:39:05 -05:00

Rx channel demods: prevent possible reading past audio buffer end - take 2. For #1661

This commit is contained in:
f4exb 2023-04-25 23:09:42 +02:00
parent 59e664c028
commit 3f392d3be7
26 changed files with 33 additions and 37 deletions

View File

@ -203,11 +203,11 @@ void AMDemodSink::processOneSample(Complex &ci)
if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
std:;size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], std::min(m_audioBufferFill, m_audioBuffer.size()));
if (res != m_audioBufferFill)
{
qDebug("AMDemodSink::processOneSample: %u/%u audio samples written", res, m_audioBufferFill);
qDebug("AMDemodSink::processOneSample: %lu/%lu audio samples written", res, m_audioBufferFill);
m_audioFifo.clear();
}

View File

@ -124,7 +124,7 @@ private:
AudioVector m_audioBuffer;
AudioFifo m_audioFifo;
uint32_t m_audioBufferFill;
std::size_t m_audioBufferFill;
QVector<qint16> m_demodBuffer;
int m_demodBufferFill;

View File

@ -225,10 +225,10 @@ void BFMDemodSink::feed(const SampleVector::const_iterator& begin, const SampleV
if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
std::size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], std::min(m_audioBufferFill, m_audioBuffer.size()));
if(res != m_audioBufferFill) {
qDebug("BFMDemodSink::feed: %u/%u audio samples written", res, m_audioBufferFill);
qDebug("BFMDemodSink::feed: %lu/%lu audio samples written", res, m_audioBufferFill);
}
m_audioBufferFill = 0;

View File

@ -114,7 +114,7 @@ private:
int m_audioSampleRate;
AudioVector m_audioBuffer;
uint m_audioBufferFill;
std::size_t m_audioBufferFill;
AudioFifo m_audioFifo;
SampleVector m_sampleBuffer;

View File

@ -446,11 +446,11 @@ void DABDemodSink::processOneAudioSample(Complex &ci)
if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
std::size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], std::min(m_audioBufferFill, m_audioBuffer.size()));
if (res != m_audioBufferFill)
{
qDebug("DABDemodSink::audio: %u/%u audio samples written", res, m_audioBufferFill);
qDebug("DABDemodSink::audio: %lu/%lu audio samples written", res, m_audioBufferFill);
m_audioFifo.clear();
}

View File

@ -140,7 +140,7 @@ private:
Real m_audioInterpolatorDistanceRemain;
AudioVector m_audioBuffer;
AudioFifo m_audioFifo;
uint32_t m_audioBufferFill;
std::size_t m_audioBufferFill;
QVector<qint16> m_demodBuffer;
int m_demodBufferFill;

View File

@ -64,7 +64,6 @@ DSDDemodSink::DSDDemodSink() :
m_signalFormat(signalFormatNone)
{
m_audioBuffer.resize(1<<14);
m_audioBufferFill = 0;
m_demodBuffer.resize(1<<12);
m_demodBufferFill = 0;

View File

@ -141,7 +141,6 @@ private:
SampleVector m_scopeSampleBuffer;
AudioVector m_audioBuffer;
uint m_audioBufferFill;
FixReal *m_sampleBuffer; //!< samples ring buffer
int m_sampleBufferIndex;
int m_scaleFromShort;

View File

@ -330,10 +330,10 @@ void FreeDVDemodSink::pushSampleToAudio(int16_t sample)
if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
std::size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], std::min(m_audioBufferFill, m_audioBuffer.size()));
if (res != m_audioBufferFill) {
qDebug("FreeDVDemodSink::pushSampleToAudio: %u/%u samples written", res, m_audioBufferFill);
qDebug("FreeDVDemodSink::pushSampleToAudio: %lu/%lu samples written", res, m_audioBufferFill);
}
m_audioBufferFill = 0;

View File

@ -182,7 +182,7 @@ private:
SampleVector m_sampleBuffer;
AudioVector m_audioBuffer;
uint m_audioBufferFill;
std::size_t m_audioBufferFill;
AudioFifo m_audioFifo;
struct freedv *m_freeDV;

View File

@ -316,11 +316,11 @@ void ILSDemodSink::processOneAudioSample(Complex &ci)
if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
std::size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], std::min(m_audioBufferFill, m_audioBuffer.size()));
if (res != m_audioBufferFill)
{
qDebug("ILSDemodSink::processOneAudioSample: %u/%u audio samples written", res, m_audioBufferFill);
qDebug("ILSDemodSink::processOneAudioSample: %lu/%lu audio samples written", res, m_audioBufferFill);
m_audioFifo.clear();
}

View File

@ -149,7 +149,7 @@ private:
Real m_audioInterpolatorDistanceRemain;
AudioVector m_audioBuffer;
AudioFifo m_audioFifo;
uint32_t m_audioBufferFill;
std::size_t m_audioBufferFill;
SampleVector m_sampleBuffer;
static const int m_sampleBufferSize = ILSDemodSettings::ILSDEMOD_CHANNEL_SAMPLE_RATE / 20;

View File

@ -520,10 +520,10 @@ void M17DemodProcessor::processAudio(const std::array<int16_t, 160>& in)
if (m_audioBufferFill >= m_audioBuffer.size() - 960)
{
uint res = m_audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
std::size_t res = m_audioFifo->write((const quint8*)&m_audioBuffer[0], std::min(m_audioBufferFill, m_audioBuffer.size()));
if (res != m_audioBufferFill) {
qDebug("M17DemodProcessor::processAudio: %u/%u audio samples written", res, m_audioBufferFill);
qDebug("M17DemodProcessor::processAudio: %lu/%lu audio samples written", res, m_audioBufferFill);
}
m_audioBufferFill = 0;

View File

@ -117,7 +117,7 @@ private:
AudioFifo *m_audioFifo;
bool m_audioMute;
AudioVector m_audioBuffer;
uint m_audioBufferFill;
std::size_t m_audioBufferFill;
float m_volume;
int m_upsampling; //!< upsampling factor
float m_upsamplingFactors[7];

View File

@ -60,7 +60,6 @@ M17DemodSink::M17DemodSink() :
m_scopeEnabled(true)
{
m_audioBuffer.resize(1<<14);
m_audioBufferFill = 0;
m_demodBuffer.resize(1<<12);
m_demodBufferFill = 0;
m_m17DemodProcessor.setAudioFifo(&m_audioFifo);

View File

@ -167,7 +167,6 @@ private:
SampleVector m_scopeSampleBuffer;
AudioVector m_audioBuffer;
uint m_audioBufferFill;
FixReal *m_sampleBuffer; //!< samples ring buffer
int m_sampleBufferIndex;
int m_scaleFromShort;

View File

@ -244,11 +244,11 @@ void NFMDemodSink::processOneSample(Complex &ci)
if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
std::size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], std::min(m_audioBufferFill, m_audioBuffer.size()));
if (res != m_audioBufferFill)
{
qDebug("NFMDemodSink::processOneSample: %u/%u audio samples written m_audioSampleRate: %u m_channelSampleRate: %d",
qDebug("NFMDemodSink::processOneSample: %lu/%lu audio samples written m_audioSampleRate: %u m_channelSampleRate: %d",
res, m_audioBufferFill, m_audioSampleRate, m_channelSampleRate);
}

View File

@ -103,7 +103,7 @@ private:
int m_audioSampleRate;
AudioVector m_audioBuffer;
uint m_audioBufferFill;
std::size_t m_audioBufferFill;
AudioFifo m_audioFifo;
QVector<qint16> m_demodBuffer;
int m_demodBufferFill;

View File

@ -241,10 +241,10 @@ void SSBDemodSink::processOneSample(Complex &ci)
if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
std::size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], std::min(m_audioBufferFill, m_audioBuffer.size()));
if (res != m_audioBufferFill) {
qDebug("SSBDemodSink::processOneSample: %u/%u samples written", res, m_audioBufferFill);
qDebug("SSBDemodSink::processOneSample: %lu/%lu samples written", res, m_audioBufferFill);
}
m_audioBufferFill = 0;

View File

@ -121,7 +121,7 @@ private:
SampleVector m_sampleBuffer;
AudioVector m_audioBuffer;
uint m_audioBufferFill;
std::size_t m_audioBufferFill;
AudioFifo m_audioFifo;
quint32 m_audioSampleRate;

View File

@ -149,11 +149,11 @@ void VORDemodSCSink::processOneAudioSample(Complex &ci)
if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
std::size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], std::min(m_audioBufferFill, m_audioBuffer.size()));
if (res != m_audioBufferFill)
{
qDebug("VORDemodSCSink::processOneAudioSample: %u/%u audio samples written", res, m_audioBufferFill);
qDebug("VORDemodSCSink::processOneAudioSample: %lu/%lu audio samples written", res, m_audioBufferFill);
m_audioFifo.clear();
}

View File

@ -115,7 +115,7 @@ private:
Real m_audioInterpolatorDistanceRemain;
AudioVector m_audioBuffer;
AudioFifo m_audioFifo;
uint32_t m_audioBufferFill;
std::size_t m_audioBufferFill;
NCO m_ncoRef;
Lowpass<Complex> m_lowpassRef;

View File

@ -126,10 +126,10 @@ void WFMDemodSink::feed(const SampleVector::const_iterator& begin, const SampleV
if(m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
std::size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], std::min(m_audioBufferFill, m_audioBuffer.size()));
if (res != m_audioBufferFill) {
qDebug("WFMDemodSink::feed: %u/%u audio samples written", res, m_audioBufferFill);
qDebug("WFMDemodSink::feed: %lu/%lu audio samples written", res, m_audioBufferFill);
}
m_audioBufferFill = 0;

View File

@ -114,7 +114,7 @@ private:
Real m_fmExcursion;
AudioVector m_audioBuffer;
uint m_audioBufferFill;
std::size_t m_audioBufferFill;
AudioFifo m_audioFifo;
PhaseDiscriminators m_phaseDiscri;

View File

@ -314,10 +314,10 @@ void UDPSinkSink::audioReadyRead()
if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
std::size_t res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], std::min(m_audioBufferFill, m_sampleBuffer.size()));
if (res != m_audioBufferFill) {
qDebug("UDPSinkSink::audioReadyRead: (stereo) lost %u samples", m_audioBufferFill - res);
qDebug("WFMDemodSink::feed: %lu/%lu audio samples written", res, m_audioBufferFill);
}
m_audioBufferFill = 0;

View File

@ -104,7 +104,7 @@ private:
UDPSinkUtil<Sample24> *m_udpBuffer24;
AudioVector m_audioBuffer;
uint m_audioBufferFill;
std::size_t m_audioBufferFill;
AudioFifo m_audioFifo;
BasebandSampleSink* m_spectrum;