From fe785c51a70ee8752a984f3d9c3960e126455ceb Mon Sep 17 00:00:00 2001 From: Xavier Roche Date: Fri, 26 Jun 2026 21:41:41 +0200 Subject: [PATCH] filtersize self-test: parse the size with sscanf(LLintP), and lock the '>' operator Use the portable sscanf(argv[0], LLintP, &sz) idiom the rest of the tree uses to read an LLint, instead of strtoll: LLint is not always long long (MSVC __int64, plus fallbacks) and strtoll is absent on old MSVC. Add two cases so the size-rule scan-time neutrality is pinned for the '>' operator too, not only '<': -*.jpg*[>10] stays neutral at scan time and cancels once the size is known. Co-Authored-By: Claude Opus 4.8 Signed-off-by: Xavier Roche --- src/htsselftest.c | 4 +++- tests/01_engine-filter.test | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/htsselftest.c b/src/htsselftest.c index c7c0287d..7e8c17ed 100644 --- a/src/htsselftest.c +++ b/src/htsselftest.c @@ -537,7 +537,9 @@ static int st_filtersize(httrackp *opt, int argc, char **argv) { return 1; } known = (argv[0][0] != '-'); /* "-1"/"-" => size unknown */ - sz = known ? (LLint) strtoll(argv[0], NULL, 10) : -1; + sz = -1; + if (known) + sscanf(argv[0], LLintP, &sz); verdict = fa_strjoker(0, &argv[2], argc - 2, argv[1], known ? &sz : NULL, known ? &size_flag : NULL, NULL); printf("verdict=%s size_flag=%d\n", diff --git a/tests/01_engine-filter.test b/tests/01_engine-filter.test index ed259dbe..528592bb 100755 --- a/tests/01_engine-filter.test +++ b/tests/01_engine-filter.test @@ -84,6 +84,9 @@ fsize 'verdict=allowed size_flag=0' -1 foo.jpg -* '+*.jpg' '-*.jpg*[<10]' # sc fsize 'verdict=forbidden size_flag=1' 5 foo.jpg -* '+*.jpg' '-*.jpg*[<10]' # <10KB: cancel fsize 'verdict=allowed size_flag=1' 20 foo.jpg -* '+*.jpg' '-*.jpg*[<10]' # >=10KB: keep fsize 'verdict=forbidden size_flag=0' -1 foo.txt -* '+*.jpg' '-*.jpg*[<10]' # not a jpg +# the '>' operator is just as neutral at scan time, and fires once size is known +fsize 'verdict=allowed size_flag=0' -1 foo.jpg -* '+*.jpg' '-*.jpg*[>10]' # scan time: keep +fsize 'verdict=forbidden size_flag=1' 20 foo.jpg -* '+*.jpg' '-*.jpg*[>10]' # >10KB: cancel # [name]/[file]/[path] never span '?' mid-string; a trailing query is still # tolerated by the global '?' rule (same as plain *.aspx), not the class (#144).