From 59e664c0289eb7315c3b790c9f8961c1a076119b Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 25 Apr 2023 20:27:57 +0200 Subject: [PATCH] Revert "Rx channel demods: prevent possible reading past audio buffer end. For #1661" This reverts commit 91f48444523c2225d2c4a84670c43020786506ea. --- plugins/channelrx/demodam/amdemodsink.cpp | 10 +++------- plugins/channelrx/demodbfm/bfmdemodsink.cpp | 10 +++------- plugins/channelrx/demoddab/dabdemodsink.cpp | 10 +++------- plugins/channelrx/demoddsd/dsddemodsink.cpp | 1 + plugins/channelrx/demoddsd/dsddemodsink.h | 1 + plugins/channelrx/demodfreedv/freedvdemodsink.cpp | 10 +++------- plugins/channelrx/demodils/ilsdemodsink.cpp | 10 +++------- plugins/channelrx/demodm17/m17demodprocessor.cpp | 10 +++------- plugins/channelrx/demodm17/m17demodsink.cpp | 1 + plugins/channelrx/demodm17/m17demodsink.h | 1 + plugins/channelrx/demodnfm/nfmdemodsink.cpp | 12 ++++-------- plugins/channelrx/demodssb/ssbdemodsink.cpp | 10 +++------- plugins/channelrx/demodvor/vordemodsink.cpp | 10 +++------- plugins/channelrx/demodwfm/wfmdemodsink.cpp | 10 +++------- plugins/channelrx/udpsink/udpsinksink.cpp | 10 +++------- 15 files changed, 38 insertions(+), 78 deletions(-) diff --git a/plugins/channelrx/demodam/amdemodsink.cpp b/plugins/channelrx/demodam/amdemodsink.cpp index a792553456..4e3cdea830 100644 --- a/plugins/channelrx/demodam/amdemodsink.cpp +++ b/plugins/channelrx/demodam/amdemodsink.cpp @@ -203,15 +203,11 @@ void AMDemodSink::processOneSample(Complex &ci) if (m_audioBufferFill >= m_audioBuffer.size()) { - 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()); + uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); - if (res != m_audioBuffer.size()) + if (res != m_audioBufferFill) { - qDebug("AMDemodSink::processOneSample: %u/%lu audio samples written", res, m_audioBuffer.size()); + qDebug("AMDemodSink::processOneSample: %u/%u audio samples written", res, m_audioBufferFill); m_audioFifo.clear(); } diff --git a/plugins/channelrx/demodbfm/bfmdemodsink.cpp b/plugins/channelrx/demodbfm/bfmdemodsink.cpp index d8d1e653c0..e22acd0e21 100644 --- a/plugins/channelrx/demodbfm/bfmdemodsink.cpp +++ b/plugins/channelrx/demodbfm/bfmdemodsink.cpp @@ -225,14 +225,10 @@ void BFMDemodSink::feed(const SampleVector::const_iterator& begin, const SampleV if (m_audioBufferFill >= m_audioBuffer.size()) { - 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()); + uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); - if(res != m_audioBuffer.size()) { - qDebug("BFMDemodSink::feed: %u/%lu audio samples written", res, m_audioBuffer.size()); + if(res != m_audioBufferFill) { + qDebug("BFMDemodSink::feed: %u/%u audio samples written", res, m_audioBufferFill); } m_audioBufferFill = 0; diff --git a/plugins/channelrx/demoddab/dabdemodsink.cpp b/plugins/channelrx/demoddab/dabdemodsink.cpp index 94549444c1..f73e4a59a6 100644 --- a/plugins/channelrx/demoddab/dabdemodsink.cpp +++ b/plugins/channelrx/demoddab/dabdemodsink.cpp @@ -446,15 +446,11 @@ void DABDemodSink::processOneAudioSample(Complex &ci) if (m_audioBufferFill >= m_audioBuffer.size()) { - 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()); + uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); - if (res != m_audioBuffer.size()) + if (res != m_audioBufferFill) { - qDebug("DABDemodSink::processOneAudioSample: %u/%lu audio samples written", res, m_audioBuffer.size()); + qDebug("DABDemodSink::audio: %u/%u audio samples written", res, m_audioBufferFill); m_audioFifo.clear(); } diff --git a/plugins/channelrx/demoddsd/dsddemodsink.cpp b/plugins/channelrx/demoddsd/dsddemodsink.cpp index 5ce1a70fbc..3a43e65830 100644 --- a/plugins/channelrx/demoddsd/dsddemodsink.cpp +++ b/plugins/channelrx/demoddsd/dsddemodsink.cpp @@ -63,6 +63,7 @@ DSDDemodSink::DSDDemodSink() : m_dsdDecoder(), m_signalFormat(signalFormatNone) { + m_audioBuffer.resize(1<<14); m_audioBufferFill = 0; m_demodBuffer.resize(1<<12); m_demodBufferFill = 0; diff --git a/plugins/channelrx/demoddsd/dsddemodsink.h b/plugins/channelrx/demoddsd/dsddemodsink.h index 31ae0d6730..a9dd2780ba 100644 --- a/plugins/channelrx/demoddsd/dsddemodsink.h +++ b/plugins/channelrx/demoddsd/dsddemodsink.h @@ -140,6 +140,7 @@ 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; diff --git a/plugins/channelrx/demodfreedv/freedvdemodsink.cpp b/plugins/channelrx/demodfreedv/freedvdemodsink.cpp index 4379bf803b..fdbcd0422e 100644 --- a/plugins/channelrx/demodfreedv/freedvdemodsink.cpp +++ b/plugins/channelrx/demodfreedv/freedvdemodsink.cpp @@ -330,14 +330,10 @@ void FreeDVDemodSink::pushSampleToAudio(int16_t sample) if (m_audioBufferFill >= m_audioBuffer.size()) { - 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()); + uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); - if (res != m_audioBuffer.size()) { - qDebug("FreeDVDemodSink::pushSampleToAudio: %u/%lu samples written", res, m_audioBuffer.size()); + if (res != m_audioBufferFill) { + qDebug("FreeDVDemodSink::pushSampleToAudio: %u/%u samples written", res, m_audioBufferFill); } m_audioBufferFill = 0; diff --git a/plugins/channelrx/demodils/ilsdemodsink.cpp b/plugins/channelrx/demodils/ilsdemodsink.cpp index b61c971ec6..cbb9b629d9 100644 --- a/plugins/channelrx/demodils/ilsdemodsink.cpp +++ b/plugins/channelrx/demodils/ilsdemodsink.cpp @@ -316,15 +316,11 @@ void ILSDemodSink::processOneAudioSample(Complex &ci) if (m_audioBufferFill >= m_audioBuffer.size()) { - 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()); + uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); - if (res != m_audioBuffer.size()) + if (res != m_audioBufferFill) { - qDebug("ILSDemodSink::processOneAudioSample: %u/%lu audio samples written", res, m_audioBuffer.size()); + qDebug("ILSDemodSink::processOneAudioSample: %u/%u audio samples written", res, m_audioBufferFill); m_audioFifo.clear(); } diff --git a/plugins/channelrx/demodm17/m17demodprocessor.cpp b/plugins/channelrx/demodm17/m17demodprocessor.cpp index 439288903d..8637ca4e58 100644 --- a/plugins/channelrx/demodm17/m17demodprocessor.cpp +++ b/plugins/channelrx/demodm17/m17demodprocessor.cpp @@ -520,14 +520,10 @@ void M17DemodProcessor::processAudio(const std::array& in) if (m_audioBufferFill >= m_audioBuffer.size() - 960) { - 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()); + uint res = m_audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); - if (res != m_audioBuffer.size()) { - qDebug("M17DemodProcessor::processAudio: %u/%lu audio samples written", res, m_audioBuffer.size()); + if (res != m_audioBufferFill) { + qDebug("M17DemodProcessor::processAudio: %u/%u audio samples written", res, m_audioBufferFill); } m_audioBufferFill = 0; diff --git a/plugins/channelrx/demodm17/m17demodsink.cpp b/plugins/channelrx/demodm17/m17demodsink.cpp index 77e88bdf9a..88aa0dbfd7 100644 --- a/plugins/channelrx/demodm17/m17demodsink.cpp +++ b/plugins/channelrx/demodm17/m17demodsink.cpp @@ -59,6 +59,7 @@ M17DemodSink::M17DemodSink() : m_scopeXY(nullptr), m_scopeEnabled(true) { + m_audioBuffer.resize(1<<14); m_audioBufferFill = 0; m_demodBuffer.resize(1<<12); m_demodBufferFill = 0; diff --git a/plugins/channelrx/demodm17/m17demodsink.h b/plugins/channelrx/demodm17/m17demodsink.h index 9d37f4072d..bd0bc50811 100644 --- a/plugins/channelrx/demodm17/m17demodsink.h +++ b/plugins/channelrx/demodm17/m17demodsink.h @@ -166,6 +166,7 @@ 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; diff --git a/plugins/channelrx/demodnfm/nfmdemodsink.cpp b/plugins/channelrx/demodnfm/nfmdemodsink.cpp index c0b32d9f65..9bbd55ec47 100644 --- a/plugins/channelrx/demodnfm/nfmdemodsink.cpp +++ b/plugins/channelrx/demodnfm/nfmdemodsink.cpp @@ -244,16 +244,12 @@ void NFMDemodSink::processOneSample(Complex &ci) if (m_audioBufferFill >= m_audioBuffer.size()) { - 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()); + uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); - if (res != m_audioBuffer.size()) + if (res != m_audioBufferFill) { - qDebug("NFMDemodSink::processOneSample: %u/%lu audio samples written m_audioSampleRate: %u m_channelSampleRate: %d", - res, m_audioBuffer.size(), m_audioSampleRate, m_channelSampleRate); + qDebug("NFMDemodSink::processOneSample: %u/%u audio samples written m_audioSampleRate: %u m_channelSampleRate: %d", + res, m_audioBufferFill, m_audioSampleRate, m_channelSampleRate); } m_audioBufferFill = 0; diff --git a/plugins/channelrx/demodssb/ssbdemodsink.cpp b/plugins/channelrx/demodssb/ssbdemodsink.cpp index f29429bf03..389328cbab 100644 --- a/plugins/channelrx/demodssb/ssbdemodsink.cpp +++ b/plugins/channelrx/demodssb/ssbdemodsink.cpp @@ -241,14 +241,10 @@ void SSBDemodSink::processOneSample(Complex &ci) if (m_audioBufferFill >= m_audioBuffer.size()) { - 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()); + uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); - if (res != m_audioBuffer.size()) { - qDebug("SSBDemodSink::processOneSample: %u/%lu samples written", res, m_audioBuffer.size()); + if (res != m_audioBufferFill) { + qDebug("SSBDemodSink::processOneSample: %u/%u samples written", res, m_audioBufferFill); } m_audioBufferFill = 0; diff --git a/plugins/channelrx/demodvor/vordemodsink.cpp b/plugins/channelrx/demodvor/vordemodsink.cpp index 50270113ab..18b9e21531 100644 --- a/plugins/channelrx/demodvor/vordemodsink.cpp +++ b/plugins/channelrx/demodvor/vordemodsink.cpp @@ -149,15 +149,11 @@ void VORDemodSCSink::processOneAudioSample(Complex &ci) if (m_audioBufferFill >= m_audioBuffer.size()) { - 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()); + uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); - if (res != m_audioBuffer.size()) + if (res != m_audioBufferFill) { - qDebug("VORDemodSCSink::processOneAudioSample: %u/%lu audio samples written", res, m_audioBuffer.size()); + qDebug("VORDemodSCSink::processOneAudioSample: %u/%u audio samples written", res, m_audioBufferFill); m_audioFifo.clear(); } diff --git a/plugins/channelrx/demodwfm/wfmdemodsink.cpp b/plugins/channelrx/demodwfm/wfmdemodsink.cpp index 6595fd9e56..2a71f81589 100644 --- a/plugins/channelrx/demodwfm/wfmdemodsink.cpp +++ b/plugins/channelrx/demodwfm/wfmdemodsink.cpp @@ -126,14 +126,10 @@ void WFMDemodSink::feed(const SampleVector::const_iterator& begin, const SampleV if(m_audioBufferFill >= m_audioBuffer.size()) { - 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()); + uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); - if (res != m_audioBuffer.size()) { - qDebug("WFMDemodSink::feed: %u/%lu audio samples written", res, m_audioBuffer.size()); + if (res != m_audioBufferFill) { + qDebug("WFMDemodSink::feed: %u/%u audio samples written", res, m_audioBufferFill); } m_audioBufferFill = 0; diff --git a/plugins/channelrx/udpsink/udpsinksink.cpp b/plugins/channelrx/udpsink/udpsinksink.cpp index c9c2c22982..d8f3eea5f1 100644 --- a/plugins/channelrx/udpsink/udpsinksink.cpp +++ b/plugins/channelrx/udpsink/udpsinksink.cpp @@ -314,14 +314,10 @@ void UDPSinkSink::audioReadyRead() if (m_audioBufferFill >= m_audioBuffer.size()) { - if (m_audioBufferFill > m_audioBuffer.size()) { - qDebug("UDPSinkSink::audioReadyRead: dropping %d samples", (int) m_audioBufferFill - (int) m_audioBuffer.size()); - } - - uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBuffer.size()); + uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill); - if (res != m_audioBuffer.size()) { - qDebug("UDPSinkSink::audioReadyRead: %u/%lu audio samples written", res, m_audioBuffer.size()); + if (res != m_audioBufferFill) { + qDebug("UDPSinkSink::audioReadyRead: (stereo) lost %u samples", m_audioBufferFill - res); } m_audioBufferFill = 0;