From 15720f9ab20d41d7ba316e8e174f2bc1d2b611dc Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 11 Nov 2026 07:24:45 +0400 Subject: pica-client: impose limits on partial frames --- pica-client/videodevice.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'pica-client/videodevice.cpp') diff --git a/pica-client/videodevice.cpp b/pica-client/videodevice.cpp index 67094aa..ac9a861 100644 --- a/pica-client/videodevice.cpp +++ b/pica-client/videodevice.cpp @@ -615,6 +615,11 @@ QList VideoDevice::CaptureFormats(const QString &device) return result; } +// A reassembled frame never legitimately approaches this; a stream that does +// is a peer flooding fragments that never carry the last-fragment flag, so the +// partial frame is dropped and reassembly resynchronizes at the next boundary. +static const int kMaxAssembledFrameBytes = 4 * 1024 * 1024; + VideoFrameAssembler::VideoFrameAssembler() : m_timestamp(0), m_lastSeq(0) { @@ -694,6 +699,19 @@ QByteArray VideoFrameAssembler::addFragment(quint16 seq_num, quint32 timestamp, m_buffer.clear(); m_buffer.append(data); + + /* Bound the partial frame: a peer that never sets the last-fragment flag + * would otherwise grow this without limit. Drop it and resync at the next + * frame boundary, exactly as for a lost fragment above. + */ + if (m_buffer.size() > kMaxAssembledFrameBytes) + { + m_buffer.clear(); + m_inProgress = false; + m_lastWasFrameEnd = false; + return QByteArray(); + } + m_timestamp = timestamp; m_inProgress = true; m_lastWasFrameEnd = isLast; -- cgit v1.2.1