diff options
| author | Anton <anton@picapica.im> | 2026-11-11 07:22:19 +0400 |
|---|---|---|
| committer | Anton <anton@picapica.im> | 2026-11-11 07:22:19 +0400 |
| commit | 5ead3432dba8c0e2724f796c9765612a7bf36a31 (patch) | |
| tree | c7b238cf823c266e59cb7f33367770f2d8ed7163 | |
| parent | 5d70834359245f0350496abfa08ca86de3847780 (diff) | |
| download | pica-pica-5ead3432dba8c0e2724f796c9765612a7bf36a31.tar.gz pica-pica-5ead3432dba8c0e2724f796c9765612a7bf36a31.zip | |
pica-client: codec names from the allow list only
| -rw-r--r-- | pica-client/audiovideocallcontroller.cpp | 16 | ||||
| -rw-r--r-- | pica-client/callsettings.cpp | 23 | ||||
| -rw-r--r-- | pica-client/callsettings.h | 7 |
3 files changed, 46 insertions, 0 deletions
diff --git a/pica-client/audiovideocallcontroller.cpp b/pica-client/audiovideocallcontroller.cpp index 5b3c05c..8f7c8df 100644 --- a/pica-client/audiovideocallcontroller.cpp +++ b/pica-client/audiovideocallcontroller.cpp @@ -483,6 +483,14 @@ void AudioVideoCallController::incoming_audio_params(QByteArray peer_id, QString if (!is_active || peer_id != m_peer_id) return; + // The codec name is peer-supplied and would otherwise be handed straight + // to the FFmpeg decoder - accept only the ones the client itself sends. + if (!callAudioCodecAccepted(codec)) + { + qWarning() << "rejecting unsupported call audio codec from peer:" << codec; + return; + } + Settings st(config_dbname); QString playDev = st.loadValue("audio.playback_device", "default").toString(); @@ -578,6 +586,14 @@ void AudioVideoCallController::incoming_video_params(QByteArray peer_id, QString if (!is_active || peer_id != m_peer_id) return; + // As in incoming_audio_params(): the peer-supplied codec name must be one + // we actually send before it reaches avcodec_find_decoder_by_name(). + if (!callVideoCodecAccepted(codec)) + { + qWarning() << "rejecting unsupported call video codec from peer:" << codec; + return; + } + Settings st(config_dbname); const CallSettings cs = CallSettings::load(); bool vaapiRendering = st.loadValue("video.vaapi_rendering", 0).toBool(); diff --git a/pica-client/callsettings.cpp b/pica-client/callsettings.cpp index 586fbae..dff72f4 100644 --- a/pica-client/callsettings.cpp +++ b/pica-client/callsettings.cpp @@ -36,6 +36,29 @@ const CallCodecInfo kCallAudioCodecs[] = const int kCallAudioCodecCount = sizeof(kCallAudioCodecs) / sizeof(kCallAudioCodecs[0]); +bool callAudioCodecAccepted(const QString &codec) +{ + for (int i = 0; i < kCallAudioCodecCount; i++) + if (codec == QLatin1String(kCallAudioCodecs[i].name)) + return true; + + return false; +} + +bool callVideoCodecAccepted(const QString &codec) +{ + for (int i = 0; i < kCallVideoCodecCount; i++) + if (codec == QLatin1String(kCallVideoCodecs[i].name)) + return true; + + // A camera's own compressed stream is forwarded untouched, so a sender may + // legitimately name a capture format that is not in the encode list. + if (codec == QLatin1String("mjpeg")) + return true; + + return false; +} + int callAudioSampleRate(const QString &codec) { // G.722 is a 16kHz codec by definition - it subband-codes a 7kHz audio diff --git a/pica-client/callsettings.h b/pica-client/callsettings.h index 868b156..76a36b0 100644 --- a/pica-client/callsettings.h +++ b/pica-client/callsettings.h @@ -131,4 +131,11 @@ bool callAudioBitrateAdjustable(const QString &codec); // true for, which returns the configured value instead. int callAudioFixedBitrateKbps(const QString &codec); +// Whether a codec name received in a 0x74/0x75 message is one we will hand to +// the FFmpeg decoder. Restricting this to the codecs the client itself sends +// keeps a peer from selecting an arbitrary (possibly buggy) decoder out of the +// whole FFmpeg build. +bool callAudioCodecAccepted(const QString &codec); +bool callVideoCodecAccepted(const QString &codec); + #endif // CALLSETTINGS_H |
