Skip to content

Commit 4052f42

Browse files
authored
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.
1 parent 278f21b commit 4052f42

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy

+4-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public abstract class GenerateProtoTask extends DefaultTask {
7676
// Windows CreateProcess has command line limit of 32768:
7777
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
7878
static final int WINDOWS_CMD_LENGTH_LIMIT = 32760
79+
// Most OSs impose some kind of command length limit.
80+
// Rather than account for all cases, pick a reasonable default of 64K.
81+
static final int DEFAULT_CMD_LENGTH_LIMIT = 65536
7982
// Extra command line length when added an additional argument on Windows.
8083
// Two quotes and a space.
8184
static final int CMD_ARGUMENT_EXTRA_LENGTH = 3
@@ -207,7 +210,7 @@ public abstract class GenerateProtoTask extends DefaultTask {
207210
}
208211

209212
static int getCmdLengthLimit(String os) {
210-
return isWindows(os) ? WINDOWS_CMD_LENGTH_LIMIT : Integer.MAX_VALUE
213+
return isWindows(os) ? WINDOWS_CMD_LENGTH_LIMIT : DEFAULT_CMD_LENGTH_LIMIT
211214
}
212215

213216
static boolean isWindows(String os) {

src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,8 @@ class ProtobufJavaPluginTest extends Specification {
560560
561561
int limit = GenerateProtoTask.getCmdLengthLimit(os)
562562
563-
then: "it returns maximum integer value"
564-
limit == Integer.MAX_VALUE
563+
then: "it returns default limit"
564+
limit == GenerateProtoTask.DEFAULT_CMD_LENGTH_LIMIT
565565
}
566566
567567
private Project setupBasicProject() {

0 commit comments

Comments
 (0)