This is an automated email from the ASF dual-hosted git repository.

SbloodyS pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new cf5704616f [Improvement-18412][api] Fix missing validation for 
resource preview limit parameter (#18411)
cf5704616f is described below

commit cf5704616fb9046ddf3958651cd3d55703e39f08
Author: destinyoooo <[email protected]>
AuthorDate: Tue Jul 14 00:00:29 2026 +0800

    [Improvement-18412][api] Fix missing validation for resource preview limit 
parameter (#18411)
---
 .../api/controller/ResourcesController.java                 |  2 +-
 .../validator/resource/FetchFileContentDtoValidator.java    |  3 +++
 .../resource/FetchFileContentDtoValidatorTest.java          | 13 +++++++++++++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java
index 03eb42c5d6..10825b031a 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java
@@ -314,7 +314,7 @@ public class ResourcesController extends BaseController {
         FetchFileContentRequest fetchFileContentRequest = 
FetchFileContentRequest.builder()
                 .loginUser(loginUser)
                 .resourceFileAbsolutePath(resourceAbsoluteFilePath)
-                .limit(limit == -1 ? Integer.MAX_VALUE : skipLineNum)
+                .limit(limit == -1 ? Integer.MAX_VALUE : limit)
                 .skipLineNum(skipLineNum)
                 .build();
         return 
Result.success(resourceService.fetchResourceFileContent(fetchFileContentRequest));
diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/resource/FetchFileContentDtoValidator.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/resource/FetchFileContentDtoValidator.java
index b69ec68a7c..5bdacdf7f0 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/resource/FetchFileContentDtoValidator.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/resource/FetchFileContentDtoValidator.java
@@ -37,6 +37,9 @@ public class FetchFileContentDtoValidator extends 
AbstractResourceValidator<Fetc
         if (fetchFileContentDto.getSkipLineNum() < 0) {
             throw new ServiceException("skipLineNum must be greater than or 
equal to 0");
         }
+        if (fetchFileContentDto.getLimit() != -1 && 
fetchFileContentDto.getLimit() <= 0) {
+            throw new ServiceException("limit must be -1 or greater than 0");
+        }
         String resourceFileAbsolutePath = 
fetchFileContentDto.getResourceFileAbsolutePath();
         User loginUser = fetchFileContentDto.getLoginUser();
 
diff --git 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/validator/resource/FetchFileContentDtoValidatorTest.java
 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/validator/resource/FetchFileContentDtoValidatorTest.java
index df51dd7b95..a51bdddfd6 100644
--- 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/validator/resource/FetchFileContentDtoValidatorTest.java
+++ 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/validator/resource/FetchFileContentDtoValidatorTest.java
@@ -80,6 +80,19 @@ class FetchFileContentDtoValidatorTest {
 
     }
 
+    @Test
+    void testValidate_limitInvalid() {
+        FetchFileContentDto fetchFileContentDto = FetchFileContentDto.builder()
+                .loginUser(loginUser)
+                .resourceFileAbsolutePath("/tmp")
+                .skipLineNum(0)
+                .limit(0)
+                .build();
+        assertThrowServiceException(
+                "Internal Server Error: limit must be -1 or greater than 0",
+                () -> 
fetchFileContentDtoValidator.validate(fetchFileContentDto));
+    }
+
     @Test
     void testValidate_notUnderBaseDirectory() {
         FetchFileContentDto fetchFileContentDto = FetchFileContentDto.builder()

Reply via email to