From 7a69db774d20aef873d0221bae2033ed257f184e Mon Sep 17 00:00:00 2001 From: taynpg Date: Sat, 15 Nov 2025 17:26:09 +0800 Subject: [PATCH] =?UTF-8?q?ser=EF=BC=9A=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E5=A4=A7=E9=87=8F=E6=97=A0=E6=95=88=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=97=B6=E8=B8=A2=E5=87=BA=E5=AE=A2=E6=88=B7=E7=AB=AF?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gui/main.cpp | 8 ++++---- Protocol/Protocol.h | 2 ++ Server/Server.cpp | 8 +++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Gui/main.cpp b/Gui/main.cpp index 1cb9b78..15bf26f 100644 --- a/Gui/main.cpp +++ b/Gui/main.cpp @@ -30,10 +30,10 @@ int main(int argc, char* argv[]) frelayGUI w; - QFile file(":/QtTheme/theme/Flat/Light/Blue/Pink.qss"); - if (file.open(QFile::ReadOnly)) { - a.setStyleSheet(file.readAll()); - } + // QFile file(":/QtTheme/theme/Flat/Light/Blue/Pink.qss"); + // if (file.open(QFile::ReadOnly)) { + // a.setStyleSheet(file.readAll()); + // } QObject::connect(&a, &SingleApplication::instanceStarted, &w, [&w]() { w.showNormal(); diff --git a/Protocol/Protocol.h b/Protocol/Protocol.h index 5b2f6d2..22a6878 100644 --- a/Protocol/Protocol.h +++ b/Protocol/Protocol.h @@ -13,6 +13,8 @@ constexpr quint32 CHUNK_BUF_SIZE = 1 * 1024 * 512; constexpr quint32 FLOW_BACK_MULTIPLE = 50; // 阻塞等级放大倍率 constexpr quint32 BLOCK_LEVEL_MULTIPLE = 5; +// 允许最大的无效数据包大小 +constexpr quint32 MAX_INVALID_PACKET_SIZE = CHUNK_BUF_SIZE * 5; // It is specified here that the first 30 contents (inclusive) are // used for communication with the server. diff --git a/Server/Server.cpp b/Server/Server.cpp index fab8c28..942152a 100644 --- a/Server/Server.cpp +++ b/Server/Server.cpp @@ -103,6 +103,12 @@ void Server::onReadyRead() } if (client) { + if (client->buffer.size() > MAX_INVALID_PACKET_SIZE) { + auto mg = QString("Client %1 buffer size exceeded, XXXXX...").arg(client->id); + qWarning() << mg; + socket->disconnectFromHost(); + return; + } client->buffer.append(socket->readAll()); processClientData(client); } @@ -143,7 +149,7 @@ bool Server::sendWithFlowCheck(QTcpSocket* fsoc, QTcpSocket* tsoc, QSharedPointe if (flowBackCount_[fsoc->property("clientId").toString()] > FLOW_BACK_MULTIPLE) { auto level = getBlockLevel(tsoc); flowLimit(fsoc, level); - //qDebug() << "Flow back count exceeded, block level:" << level; + // qDebug() << "Flow back count exceeded, block level:" << level; } flowBackCount_[fsoc->property("clientId").toString()]++; return sendData(tsoc, frame);