From 4a669237dd13203568710dc10d30aa23df6fc014 Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Fri, 17 Jan 2025 11:44:09 +0200 Subject: [PATCH 1/3] fix: Return error on requested unexisting offset instead of defaulting to 0 offset. --- src/webui/api/torrentscontroller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index dcf9580b69e8..1323633f2230 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -387,7 +387,7 @@ void TorrentsController::infoAction() if (offset < 0) offset = size + offset; if ((offset >= size) || (offset < 0)) - offset = 0; + throw APIError(APIErrorType::Conflict, tr("Offset is out of range")); // normalize limit if (limit <= 0) limit = -1; // unlimited From 876849cdc10faa7d6e5f7b4e009f6ebcfeb85602 Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Mon, 27 Jan 2025 14:24:36 +0200 Subject: [PATCH 2/3] Return empty list instead of error. --- src/webui/api/torrentscontroller.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index 1323633f2230..4e7bc50948cd 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -386,8 +386,10 @@ void TorrentsController::infoAction() // normalize offset if (offset < 0) offset = size + offset; - if ((offset >= size) || (offset < 0)) - throw APIError(APIErrorType::Conflict, tr("Offset is out of range")); + if ((offset >= size) || (offset < 0)) { + setResult(QJsonArray {}); + return; + } // normalize limit if (limit <= 0) limit = -1; // unlimited From 52ed311d265913b2bf58f112d2afe5f2c2c346e3 Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Mon, 27 Jan 2025 14:44:55 +0200 Subject: [PATCH 3/3] QList's mid returns an empty list if supplied limit/offset cause out-of-bound. So we dont need the condition. --- src/webui/api/torrentscontroller.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index 4e7bc50948cd..2a300752b162 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -386,10 +386,6 @@ void TorrentsController::infoAction() // normalize offset if (offset < 0) offset = size + offset; - if ((offset >= size) || (offset < 0)) { - setResult(QJsonArray {}); - return; - } // normalize limit if (limit <= 0) limit = -1; // unlimited