From b13a0f5b79f6395e3f45fbffbed11a6ca3e23e23 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Fri, 19 Nov 2021 11:27:27 +0800 Subject: [PATCH] =?UTF-8?q?Splitter:=20=E5=85=A8=E5=B1=80=E9=99=90?= =?UTF-8?q?=E5=88=B6=E5=86=85=E5=AD=98=E4=BD=BF=E7=94=A8=E9=87=8F=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E5=86=85=E5=AD=98=E6=BA=A2=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HttpRequestSplitter.cpp | 7 +++++++ src/Rtp/PSDecoder.cpp | 5 ----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Http/HttpRequestSplitter.cpp b/src/Http/HttpRequestSplitter.cpp index 6b4c0123..70a713e6 100644 --- a/src/Http/HttpRequestSplitter.cpp +++ b/src/Http/HttpRequestSplitter.cpp @@ -13,9 +13,16 @@ #include "Util/util.h" using namespace toolkit; +//协议解析最大缓存1兆数据 +static constexpr size_t kMaxCacheSize = 1 * 1024 * 1024; + namespace mediakit { void HttpRequestSplitter::input(const char *data,size_t len) { + if (remainDataSize() > kMaxCacheSize) { + //缓存太多数据无法处理则上抛异常 + throw std::out_of_range("remain data size is too huge:" + to_string(remainDataSize())); + } const char *ptr = data; if(!_remain_data.empty()){ _remain_data.append(data,len); diff --git a/src/Rtp/PSDecoder.cpp b/src/Rtp/PSDecoder.cpp index 448f1809..6da45104 100644 --- a/src/Rtp/PSDecoder.cpp +++ b/src/Rtp/PSDecoder.cpp @@ -71,11 +71,6 @@ const char *PSDecoder::onSearchPacketTail(const char *data, size_t len) { InfoL << "解析 ps 异常: bytes=" << len << ", exception=" << ex.what() << ", hex=" << hexdump(data, MIN(len, 32)); - if (remainDataSize() > 256 * 1024) { - //缓存太多数据无法处理则上抛异常 - throw; - } - return nullptr; } }