api-linter icon indicating copy to clipboard operation
api-linter copied to clipboard

panic in checkForUnusedImports

Open pcj opened this issue 2 years ago • 0 comments

While building a bazel test rule for api-linter, encountered this panic:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x130f0e7]

goroutine 1 [running]:
github.com/jhump/protoreflect/desc/protoparse.(*errorHandler).warn(...)
	/home/runner/go/pkg/mod/github.com/jhump/[email protected]/desc/protoparse/errors.go:80
github.com/jhump/protoreflect/desc/protoparse.(*linker).checkForUnusedImports(0xc0003b60f0, 0xc000036840, 0x26)
	/home/runner/go/pkg/mod/github.com/jhump/[email protected]/desc/protoparse/linker.go:921 +0x277
github.com/jhump/protoreflect/desc/protoparse.Parser.ParseFiles(0xc0003c9a70, 0x1, 0x1, 0x0, 0xc00023ad40, 0x0, 0x0, 0x1, 0xc00000daa0, 0x0, ...)
	/home/runner/go/pkg/mod/github.com/jhump/[email protected]/desc/protoparse/parser.go:238 +0x379
main.(*cli).lint(0xc0000cb740, 0xc000403bf0, 0x1e8e970, 0x1, 0x0, 0x0, 0x0)
	/home/runner/work/api-linter/api-linter/cmd/api-linter/cli.go:161 +0x3e3
main.runCLI(0xc0000ca010, 0xb, 0xb, 0x0, 0x0)
	/home/runner/work/api-linter/api-linter/cmd/api-linter/main.go:44 +0x81
main.main()
	/home/runner/work/api-linter/api-linter/cmd/api-linter/main.go:37 +0x68

Using this linter:

    http_archive(
        name = "api_linter_darwin",
        sha256 = "4055289351f4d6d69c45c5594ed21a84f04d06bb87feff9bcd6130a39ebd5503",
        urls = ["https://github.com/googleapis/api-linter/releases/download/v1.29.3/api-linter-1.29.3-darwin-amd64.tar.gz"],
        build_file_content = _api_linter_build,
    )

Test rule generates this script (more or less):

# Generated by //proto/pluto/v1:lint_test
# DO NOT EDIT


set -euo pipefail

API_LINTER_SHORT_PATH='bazel/proto/api-linter'
ARGS=('--descriptor-set-in=../com_google_protobuf/descriptor_proto-descriptor-set.proto.bin' '--descriptor-set-in=../com_google_protobuf/timestamp_proto-descriptor-set.proto.bin' '--descriptor-set-in=proto/common/common_proto-descriptor-set.proto.bin' '--descriptor-set-in=../com_google_protobuf/wrappers_proto-descriptor-set.proto.bin' '--descriptor-set-in=proto/pluto/v1/v1_proto-descriptor-set.proto.bin' '--set-exit-status' 'proto/pluto/v1/service.proto')

# find_runfile prints the location of a runfile in the source workspace,
# either by reading the symbolic link or reading the runfiles manifest.
function find_runfile {
  local runfile=$1
  if [ -f "$runfile" ]; then
    readlink "$runfile"
    return
  fi
  runfile=$(echo "$runfile" | sed -e 's!^\(\.\./\|external/\)!!')
  if grep -q "^$runfile" MANIFEST; then
    grep "^$runfile" MANIFEST | head -n 1 | cut -d' ' -f2
    return
  fi
  # printing nothing indicates failure
}

# If arguments were provided on the command line, either replace or augment the
# generated args.
if [ "${1-}" = "-args" ]; then
  shift
  ARGS+=("$@")
elif [ $# -ne 0 ]; then
  ARGS=("$@")
fi

# Invoke api-linter.
api_linter=$(find_runfile "$API_LINTER_SHORT_PATH")
if [ -z "$api_linter" ]; then
  echo "error: could not locate api-linter binary" >&2
  exit 1
fi
"$api_linter" "${ARGS[@]}"

Perhaps this is a bug in the upstream protoreflect library, but figured I'd report it.

Please let me know if I'm calling the tool incorrectly.

pcj avatar Dec 15 '21 03:12 pcj