Skip to content

ScipBuildTool and ScipOptionBuilder write unescaped Windows backslashes into double-quoted @argfile arguments, corrupting paths containing \t, \n, \r, \b, or \f #1067

Open

Description

@StrayCatDBA

When generating javac @argfile options (javacopts.txt in ScipBuildTool.kt and modified @argfile entries in ScipOptionBuilder.java), arguments containing file paths are wrapped in double quotes ("...") without escaping backslashes (\).

According to the JDK javac @argfile specification, backslash escape sequences (\t, \n, \r, \b, \f, \\, \") are interpreted inside quoted strings in @argfiles. On Windows, any path segment starting with t, n, r, b, or f (such as \target\..., C:\temp\..., \repos\..., \build\..., \foo\...) is silently corrupted into a tab, newline, carriage return, backspace, or form-feed character when javac parses @javacopts.txt.

(Note: #992 and #1012 report a similar backslash escaping issue in GradleBuildTool.kt's init-script.gradle, and #1009 covers line splitting in InjectScipOptions.java, but ScipBuildTool.kt and ScipOptionBuilder.java have the same problem when writing javac @argfiles.)

Affected Code (main)

  1. scip-java/src/main/kotlin/org/scip_code/scip_java/buildtools/ScipBuildTool.kt (lines 182–224):

    val argsfile = targetroot.resolve("javacopts.txt")
    val arguments = mutableListOf<String>()
    ...
    arguments += "-d"
    arguments += generatedDir(tmp, "d")
    ...
    arguments += "-classpath"
    arguments += classpath.joinToString(File.pathSeparator)
    arguments += "-Xplugin:scip -targetroot:$targetroot -sourceroot:$sourceroot"
    ...
    arguments += javaFiles.map { it.toString() }
    val quotedArguments = arguments.map { "\"$it\"" }
    Files.write(argsfile, quotedArguments)

    Also at line 280 (javacPath):

    return Paths.get(home, "bin", "javac") // missing .exe fallback on Windows when spawning via ProcessBuilder
  2. scip-javac/src/main/java/org/scip_code/scip_java/javac/ScipOptionBuilder.java (lines 56–78):

    private String wrapQuote(String arg) {
      if (arg.startsWith("\"") && arg.endsWith("\"")) {
        return arg;
      } else {
        return "\"" + arg + "\"";
      }
    }
    
    private String xpluginOption() {
      return String.format(
          "\"-Xplugin:scip -sourceroot:%s -targetroot:%s\"", SOURCEROOT, TARGETROOT);
    }

Steps to Reproduce

  1. On Windows, place a Java project under a directory containing \t, \n, \r, \b, or \f (e.g., C:\temp\my-project or with targetroot under <repo>\target\scip-targetroot).
  2. Run scip-java index using either ScipBuildTool (javacopts.txt) or InjectScipOptions (@argfile).
  3. javac @javacopts.txt parses "C:\temp\my-project\target\..." as "C:<TAB>emp\my-project<TAB>arget\...", failing with error: file not found / InvalidPathException / NoSuchFileException.

Suggested Fix

Escape backslashes (\ -> \\) and embedded double quotes (" -> \") before wrapping @argfile arguments in double quotes:

  • In ScipBuildTool.kt:
    val quotedArguments = arguments.map { "\"${it.replace("\\", "\\\\").replace("\"", "\\\"")}\"" }
  • In ScipOptionBuilder.java:
    private String escapeArgfileValue(String value) {
      return value.replace("\\", "\\\\").replace("\"", "\\\"");
    }
    
    private String wrapQuote(String arg) {
      if (arg.startsWith("\"") && arg.endsWith("\"")) {
        return arg;
      } else {
        return "\"" + escapeArgfileValue(arg) + "\"";
      }
    }
    
    private String xpluginOption() {
      return String.format(
          "\"-Xplugin:scip -sourceroot:%s -targetroot:%s\"",
          escapeArgfileValue(SOURCEROOT),
          escapeArgfileValue(TARGETROOT));
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions