Skip to content

Commit

Permalink
Rx channel demods: prevent possible reading past audio buffer end. For
Browse files Browse the repository at this point in the history
  • Loading branch information
f4exb committed Apr 22, 2023
1 parent 8688179 commit 91f4844
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 38 deletions.
10 changes: 7 additions & 3 deletions plugins/channelrx/demodam/amdemodsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,15 @@ void AMDemodSink::processOneSample(Complex &ci)

if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
if (m_audioBufferFill > m_audioBuffer.size()) {
qDebug("AMDemodSink::processOneSample: dropping %d samples", (int) m_audioBufferFill - (int) m_audioBuffer.size());
}

uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBuffer.size());

if (res != m_audioBufferFill)
if (res != m_audioBuffer.size())
{
qDebug("AMDemodSink::processOneSample: %u/%u audio samples written", res, m_audioBufferFill);
qDebug("AMDemodSink::processOneSample: %u/%lu audio samples written", res, m_audioBuffer.size());
m_audioFifo.clear();
}

Expand Down
10 changes: 7 additions & 3 deletions plugins/channelrx/demodbfm/bfmdemodsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,14 @@ 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);
if (m_audioBufferFill > m_audioBuffer.size()) {
qDebug("BFMDemodSink::processOneSample: dropping %d samples", (int) m_audioBufferFill - (int) m_audioBuffer.size());
}

uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBuffer.size());

if(res != m_audioBufferFill) {
qDebug("BFMDemodSink::feed: %u/%u audio samples written", res, m_audioBufferFill);
if(res != m_audioBuffer.size()) {
qDebug("BFMDemodSink::feed: %u/%lu audio samples written", res, m_audioBuffer.size());
}

m_audioBufferFill = 0;
Expand Down
10 changes: 7 additions & 3 deletions plugins/channelrx/demoddab/dabdemodsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,15 @@ void DABDemodSink::processOneAudioSample(Complex &ci)

if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
if (m_audioBufferFill > m_audioBuffer.size()) {
qDebug("DABDemodSink::processOneAudioSample: dropping %d samples", (int) m_audioBufferFill - (int) m_audioBuffer.size());
}

uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBuffer.size());

if (res != m_audioBufferFill)
if (res != m_audioBuffer.size())
{
qDebug("DABDemodSink::audio: %u/%u audio samples written", res, m_audioBufferFill);
qDebug("DABDemodSink::processOneAudioSample: %u/%lu audio samples written", res, m_audioBuffer.size());
m_audioFifo.clear();
}

Expand Down
1 change: 0 additions & 1 deletion plugins/channelrx/demoddsd/dsddemodsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ DSDDemodSink::DSDDemodSink() :
m_dsdDecoder(),
m_signalFormat(signalFormatNone)
{
m_audioBuffer.resize(1<<14);
m_audioBufferFill = 0;
m_demodBuffer.resize(1<<12);
m_demodBufferFill = 0;
Expand Down
1 change: 0 additions & 1 deletion plugins/channelrx/demoddsd/dsddemodsink.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ class DSDDemodSink : public ChannelSampleSink {
MagSqLevelsStore m_magSqLevelStore;

SampleVector m_scopeSampleBuffer;
AudioVector m_audioBuffer;
uint m_audioBufferFill;
FixReal *m_sampleBuffer; //!< samples ring buffer
int m_sampleBufferIndex;
Expand Down
10 changes: 7 additions & 3 deletions plugins/channelrx/demodfreedv/freedvdemodsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,14 @@ void FreeDVDemodSink::pushSampleToAudio(int16_t sample)

if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
if (m_audioBufferFill > m_audioBuffer.size()) {
qDebug("FreeDVDemodSink::pushSampleToAudio: dropping %d samples", (int) m_audioBufferFill - (int) m_audioBuffer.size());
}

uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBuffer.size());

if (res != m_audioBufferFill) {
qDebug("FreeDVDemodSink::pushSampleToAudio: %u/%u samples written", res, m_audioBufferFill);
if (res != m_audioBuffer.size()) {
qDebug("FreeDVDemodSink::pushSampleToAudio: %u/%lu samples written", res, m_audioBuffer.size());
}

m_audioBufferFill = 0;
Expand Down
10 changes: 7 additions & 3 deletions plugins/channelrx/demodils/ilsdemodsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,15 @@ void ILSDemodSink::processOneAudioSample(Complex &ci)

if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
if (m_audioBufferFill > m_audioBuffer.size()) {
qDebug("ILSDemodSink::processOneAudioSample: dropping %d samples", (int) m_audioBufferFill - (int) m_audioBuffer.size());
}

uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBuffer.size());

if (res != m_audioBufferFill)
if (res != m_audioBuffer.size())
{
qDebug("ILSDemodSink::processOneAudioSample: %u/%u audio samples written", res, m_audioBufferFill);
qDebug("ILSDemodSink::processOneAudioSample: %u/%lu audio samples written", res, m_audioBuffer.size());
m_audioFifo.clear();
}

Expand Down
10 changes: 7 additions & 3 deletions plugins/channelrx/demodm17/m17demodprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,14 @@ 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);
if (m_audioBufferFill > m_audioBuffer.size()) {
qDebug("M17DemodProcessor::processAudio: dropping %d samples", (int) m_audioBufferFill - (int) m_audioBuffer.size());
}

uint res = m_audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBuffer.size());

if (res != m_audioBufferFill) {
qDebug("M17DemodProcessor::processAudio: %u/%u audio samples written", res, m_audioBufferFill);
if (res != m_audioBuffer.size()) {
qDebug("M17DemodProcessor::processAudio: %u/%lu audio samples written", res, m_audioBuffer.size());
}

m_audioBufferFill = 0;
Expand Down
1 change: 0 additions & 1 deletion plugins/channelrx/demodm17/m17demodsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ M17DemodSink::M17DemodSink() :
m_scopeXY(nullptr),
m_scopeEnabled(true)
{
m_audioBuffer.resize(1<<14);
m_audioBufferFill = 0;
m_demodBuffer.resize(1<<12);
m_demodBufferFill = 0;
Expand Down
1 change: 0 additions & 1 deletion plugins/channelrx/demodm17/m17demodsink.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ class M17DemodSink : public ChannelSampleSink {
MagSqLevelsStore m_magSqLevelStore;

SampleVector m_scopeSampleBuffer;
AudioVector m_audioBuffer;
uint m_audioBufferFill;
FixReal *m_sampleBuffer; //!< samples ring buffer
int m_sampleBufferIndex;
Expand Down
12 changes: 8 additions & 4 deletions plugins/channelrx/demodnfm/nfmdemodsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,16 @@ void NFMDemodSink::processOneSample(Complex &ci)

if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
if (m_audioBufferFill > m_audioBuffer.size()) {
qDebug("NFMDemodSink::processOneSample: dropping %d samples", (int) m_audioBufferFill - (int) m_audioBuffer.size());
}

uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBuffer.size());

if (res != m_audioBufferFill)
if (res != m_audioBuffer.size())
{
qDebug("NFMDemodSink::processOneSample: %u/%u audio samples written m_audioSampleRate: %u m_channelSampleRate: %d",
res, m_audioBufferFill, m_audioSampleRate, m_channelSampleRate);
qDebug("NFMDemodSink::processOneSample: %u/%lu audio samples written m_audioSampleRate: %u m_channelSampleRate: %d",
res, m_audioBuffer.size(), m_audioSampleRate, m_channelSampleRate);
}

m_audioBufferFill = 0;
Expand Down
10 changes: 7 additions & 3 deletions plugins/channelrx/demodssb/ssbdemodsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,14 @@ void SSBDemodSink::processOneSample(Complex &ci)

if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
if (m_audioBufferFill > m_audioBuffer.size()) {
qDebug("SSBDemodSink::processOneSample: dropping %d samples", (int) m_audioBufferFill - (int) m_audioBuffer.size());
}

uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBuffer.size());

if (res != m_audioBufferFill) {
qDebug("SSBDemodSink::processOneSample: %u/%u samples written", res, m_audioBufferFill);
if (res != m_audioBuffer.size()) {
qDebug("SSBDemodSink::processOneSample: %u/%lu samples written", res, m_audioBuffer.size());
}

m_audioBufferFill = 0;
Expand Down
10 changes: 7 additions & 3 deletions plugins/channelrx/demodvor/vordemodsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,15 @@ void VORDemodSCSink::processOneAudioSample(Complex &ci)

if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
if (m_audioBufferFill > m_audioBuffer.size()) {
qDebug("VORDemodSCSink::processOneAudioSample: dropping %d samples", (int) m_audioBufferFill - (int) m_audioBuffer.size());
}

uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBuffer.size());

if (res != m_audioBufferFill)
if (res != m_audioBuffer.size())
{
qDebug("VORDemodSCSink::processOneAudioSample: %u/%u audio samples written", res, m_audioBufferFill);
qDebug("VORDemodSCSink::processOneAudioSample: %u/%lu audio samples written", res, m_audioBuffer.size());
m_audioFifo.clear();
}

Expand Down
10 changes: 7 additions & 3 deletions plugins/channelrx/demodwfm/wfmdemodsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,14 @@ 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);
if (m_audioBufferFill > m_audioBuffer.size()) {
qDebug("WFMDemodSink::feed: dropping %d samples", (int) m_audioBufferFill - (int) m_audioBuffer.size());
}

uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBuffer.size());

if (res != m_audioBufferFill) {
qDebug("WFMDemodSink::feed: %u/%u audio samples written", res, m_audioBufferFill);
if (res != m_audioBuffer.size()) {
qDebug("WFMDemodSink::feed: %u/%lu audio samples written", res, m_audioBuffer.size());
}

m_audioBufferFill = 0;
Expand Down
10 changes: 7 additions & 3 deletions plugins/channelrx/udpsink/udpsinksink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,14 @@ void UDPSinkSink::audioReadyRead()

if (m_audioBufferFill >= m_audioBuffer.size())
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill);
if (m_audioBufferFill > m_audioBuffer.size()) {
qDebug("UDPSinkSink::audioReadyRead: dropping %d samples", (int) m_audioBufferFill - (int) m_audioBuffer.size());
}

if (res != m_audioBufferFill) {
qDebug("UDPSinkSink::audioReadyRead: (stereo) lost %u samples", m_audioBufferFill - res);
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBuffer.size());

if (res != m_audioBuffer.size()) {
qDebug("UDPSinkSink::audioReadyRead: %u/%lu audio samples written", res, m_audioBuffer.size());
}

m_audioBufferFill = 0;
Expand Down

0 comments on commit 91f4844

Please sign in to comment.