Merge pull request #1527 from rootkiller6788:fix-parseparams-empty-args-oob

PiperOrigin-RevId: 971820982
diff --git a/c/tools/brotli.c b/c/tools/brotli.c
index 0de5b44..98ff0a4 100644
--- a/c/tools/brotli.c
+++ b/c/tools/brotli.c
@@ -301,11 +301,6 @@
        contain pointers to strings"; NULL and 0-length are not forbidden. */
     size_t arg_len = arg ? strlen(arg) : 0;
 
-    if (arg_len == 0) {
-      params->not_input_indices[next_option_index++] = i;
-      continue;
-    }
-
     /* Too many options. The expected longest option list is:
        "-q 0 -w 10 -o f -D d -S b -d -f -k -n -v -K --", i.e. 17 items in total.
        This check is an additional guard that is never triggered, but provides
@@ -315,6 +310,11 @@
       return COMMAND_INVALID;
     }
 
+    if (arg_len == 0) {
+      params->not_input_indices[next_option_index++] = i;
+      continue;
+    }
+
     /* Input file entry. */
     if (after_dash_dash || arg[0] != '-' || arg_len == 1) {
       input_count++;