Skip to content

pbts does not properly handle filepaths with special characters in it #2081

Open
@wyattscarpenter

Description

@wyattscarpenter

I'm contributing to another project that uses pbts. When I run yarn run --silent pbts proto.js from my project directory ~/j"oker `something` 'cool streamlit; that I made to test resiliency to special characters, I get this output:

Error: Command failed: yarn run --silent pbts proto.js
/bin/sh: 1: Syntax error: Unterminated quoted string
/home/user/j"oker `something` 'cool  streamlit;/frontend/node_modules/protobufjs-cli/pbts.js:129
                throw err;
                ^

Error: code 2
    at ChildProcess.<anonymous> (/home/user/j"oker `something` 'cool  streamlit;/frontend/node_modules/protobufjs-cli/pbts.js:126:27)
    at ChildProcess.emit (node:events:519:35)
    at maybeClose (node:internal/child_process:1101:16)
    at Socket.<anonymous> (node:internal/child_process:457:11)
    at Socket.emit (node:events:507:28)
    at Pipe.<anonymous> (node:net:346:12)

Node.js v24.2.0

Failed to generate protobuf files: Error: Command failed: yarn run --silent pbts proto.js
/bin/sh: 1: Syntax error: Unterminated quoted string
/home/user/j"oker `something` 'cool  streamlit;/frontend/node_modules/protobufjs-cli/pbts.js:129
                throw err;
                ^

Error: code 2
    at ChildProcess.<anonymous> (/home/user/j"oker `something` 'cool  streamlit;/frontend/node_modules/protobufjs-cli/pbts.js:126:27)
    at ChildProcess.emit (node:events:519:35)
    at maybeClose (node:internal/child_process:1101:16)
    at Socket.<anonymous> (node:internal/child_process:457:11)
    at Socket.emit (node:events:507:28)
    at Pipe.<anonymous> (node:net:346:12)

Node.js v24.2.0

    at genericNodeError (node:internal/errors:983:15)
    at wrappedFn (node:internal/errors:537:14)
    at ChildProcess.exithandler (node:child_process:415:12)
    at ChildProcess.emit (node:events:507:28)
    at maybeClose (node:internal/child_process:1101:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5) {
  code: 1,
  killed: false,
  signal: null,
  cmd: 'yarn run --silent pbts proto.js'
}
make: *** [Makefile:237: protobuf] Error 1

I'm happy to tell you I know exactly why this happens, after just a little sleuthing:

// There is no proper API for jsdoc, so this executes the CLI and pipes the output

Specifically, this call to exec does not escape its arguments (note that escaping arguments is generally a pretty brittle and annoying way of dealing with such problems...), so they evaluate in the shell and cause a parse error:

 function callJsdoc() {

        // There is no proper API for jsdoc, so this executes the CLI and pipes the output
        var basedir = path.join(__dirname, ".");
        var moduleName = argv.name || "null";
        var nodePath = process.execPath;
        var cmd = "\"" + nodePath + "\" \"" + require.resolve("jsdoc/jsdoc.js") + "\" -c \"" + path.join(basedir, "lib", "tsd-jsdoc.json") + "\" -q \"module=" + encodeURIComponent(moduleName) + "&comments=" + Boolean(argv.comments) + "\" " + files.map(function(file) { return "\"" + file + "\""; }).join(" ");
        var child = child_process.exec(cmd, {
            cwd: process.cwd(),
            argv0: "node",
            stdio: "pipe",
            maxBuffer: 1 << 26 // 67mb
        });

Incidentally, we also use yarn run --silent pbjs, and that has no problem.

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