From 4052f42867868557f5b174deac55eef9af7b1d61 Mon Sep 17 00:00:00 2001 From: Karthik Ramgopal Date: Sun, 8 Jan 2023 15:04:41 -0800 Subject: [PATCH] Set default command length limit to 64k (#653) Various operating systems impose command length limits that are far short of the current Integer.MAX_VALUE default. For example, on MacOS 12.6.2, getconf ARG_MAX returns 1048576. Hence set a reasonable default command line length limit of 64k. --- .../com/google/protobuf/gradle/GenerateProtoTask.groovy | 5 ++++- .../com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy index ff419f2e..c38506c9 100644 --- a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy @@ -76,6 +76,9 @@ public abstract class GenerateProtoTask extends DefaultTask { // Windows CreateProcess has command line limit of 32768: // https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx static final int WINDOWS_CMD_LENGTH_LIMIT = 32760 + // Most OSs impose some kind of command length limit. + // Rather than account for all cases, pick a reasonable default of 64K. + static final int DEFAULT_CMD_LENGTH_LIMIT = 65536 // Extra command line length when added an additional argument on Windows. // Two quotes and a space. static final int CMD_ARGUMENT_EXTRA_LENGTH = 3 @@ -207,7 +210,7 @@ public abstract class GenerateProtoTask extends DefaultTask { } static int getCmdLengthLimit(String os) { - return isWindows(os) ? WINDOWS_CMD_LENGTH_LIMIT : Integer.MAX_VALUE + return isWindows(os) ? WINDOWS_CMD_LENGTH_LIMIT : DEFAULT_CMD_LENGTH_LIMIT } static boolean isWindows(String os) { diff --git a/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy b/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy index e8f84709..8798574e 100644 --- a/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy +++ b/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy @@ -560,8 +560,8 @@ class ProtobufJavaPluginTest extends Specification { int limit = GenerateProtoTask.getCmdLengthLimit(os) - then: "it returns maximum integer value" - limit == Integer.MAX_VALUE + then: "it returns default limit" + limit == GenerateProtoTask.DEFAULT_CMD_LENGTH_LIMIT } private Project setupBasicProject() {