Skip to content

Commit

Permalink
Set default command length limit to 64k (#653)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
karthikrg authored Jan 8, 2023
1 parent 278f21b commit 4052f42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 4052f42

Please sign in to comment.