Skip to content

panic on interface conversion to int, with gocritic hugeParam sizeThreshold set #2185

Closed
@ClaudiaJ

Description

@ClaudiaJ

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).
  • Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)

Description of the problem

With golangci-lint config expressed as json or toml, setting gocritic.settings.hugeParam.sizeThreshold, golangci-lint panics if checks more than hugeParam are enabled for gocritic linter.

Minimum reproducible configs are provided as both json and toml, but the same expressed as yaml (also provided in details below) works fine.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.42.0 built from c6142e38 on 2021-08-17T11:47:22Z

Configuration file

Sample minimum reproducible TOML config:

[linters-settings.gocritic]

# with hugeParam plus at least one other check enabled, it panics
enabled-checks = ["hugeParam", "indexAlloc"]

# performance tag, which includes hugeParam and others panics
#enabled-tags = ["performance"]

# with _only_ hugeParam configured works
#enabled-checks = [ "hugeParam" ]

# but only if I also set hugeParam.sizeThreshold
[linters-settings.gocritic.settings.hugeParam]
sizeThreshold = 256

[linters]
disable-all = true
enable = [ "gocritic" ]

Sample minimum reproducible JSON config:

{
  "linters": {
    "disable-all": true,
    "enable": [
      "gocritic"
    ]
  },
  "linters-settings": {
    "gocritic": {
      "enabled-checks": [
        "hugeParam",
        "indexAlloc"
      ],
      "settings": {
        "hugeParam": {
          "sizeThreshold": 256
        }
      }
    }
  }
}

Go environment

$ go version && go env
go version go1.16.5 darwin/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hardmanc/Library/Caches/go-build"
GOENV="/Users/hardmanc/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/hardmanc/go/pkg/mod"
GONOPROXY="github.com/Mattel,gitlab.platform.mattel,go.mattel,*.go.mattel"
GONOSUMDB="github.com/Mattel,gitlab.platform.mattel,go.mattel,*.go.mattel"
GOOS="darwin"
GOPATH="/Users/hardmanc/go"
GOPRIVATE="github.com/Mattel,gitlab.platform.mattel,go.mattel,*.go.mattel"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/hardmanc/sdk/go1.16.5"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/hardmanc/sdk/go1.16.5/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/hardmanc/go/src/github.com/Mattel/mcpp/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z7/stklw781395csnym8wd6z8kdwz7__g/T/go-build1171437063=/tmp/go-build -gno-record-gcc-switches -fno-common"

Verbose output of running

Panic w/ sample TOML config:

$ golangci-lint cache clean
$ golangci-lint run -v --config .golangci.toml
INFO [config_reader] Used config file .golangci.toml
INFO [lintersdb] Active 1 linters: [gocritic]
INFO [loader] Go packages loading at mode 575 (files|imports|types_sizes|compiled_files|deps|exports_file|name) took 3.423668554s
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 78.558091ms
INFO [linters context/goanalysis] analyzers took 0s with no stages
ERRO [runner] Panic: gocritic: package "mcpp" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is int64, not int: goroutine 10712 [running]:
runtime/debug.Stack(0x4e8b00f, 0x3c, 0xc0023a0708)
        /Users/hardmanc/sdk/go1.16.5/src/runtime/debug/stack.go:24 +0x9f
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1(0xc001942000)
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/goanalysis/runner_action.go:101 +0x1be
panic(0x4c899a0, 0xc00a6f4ba0)
        /Users/hardmanc/sdk/go1.16.5/src/runtime/panic.go:965 +0x1b9
github.com/go-critic/go-critic/framework/linter.CheckerParams.Int(...)
        /Users/hardmanc/go/pkg/mod/github.com/go-critic/go-critic@v0.5.6/framework/linter/lintpack.go:54
github.com/go-critic/go-critic/checkers.init.36.func1(0xc00379c1c8, 0xc00379c1c8, 0xc0009cee00, 0x1e0000c0023a0a20, 0x411159d)
        /Users/hardmanc/go/pkg/mod/github.com/go-critic/go-critic@v0.5.6/checkers/hugeParam_checker.go:27 +0x145
github.com/go-critic/go-critic/framework/linter.addChecker.func2(0xc00a6fac30, 0xc000226a50, 0x4df5177, 0x9)
        /Users/hardmanc/go/pkg/mod/github.com/go-critic/go-critic@v0.5.6/framework/linter/checkers_db.go:79 +0xdc
github.com/go-critic/go-critic/framework/linter.newChecker(0xc00a6fac30, 0xc002f3e360, 0x0, 0x0, 0xc0009e66c8)
        /Users/hardmanc/go/pkg/mod/github.com/go-critic/go-critic@v0.5.6/framework/linter/checkers_db.go:92 +0x71
github.com/go-critic/go-critic/framework/linter.NewChecker(...)
        /Users/hardmanc/go/pkg/mod/github.com/go-critic/go-critic@v0.5.6/framework/linter/lintpack.go:144
github.com/golangci/golangci-lint/pkg/golinters.buildEnabledCheckers(0xc00415c690, 0xc00a6fac30, 0x6669636570732074, 0x726f697270206369, 0x6e65747469727720, 0x7373696d72657020, 0xa2f2f0a2e6e6f69)
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/gocritic.go:127 +0x185
github.com/golangci/golangci-lint/pkg/golinters.NewGocritic.func1.1(0xc00a6ee820, 0x119fd6fb1, 0x57a7d40, 0xc001232350, 0x2)
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/gocritic.go:44 +0x11f
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc001942000)
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/goanalysis/runner_action.go:187 +0x9f2
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/goanalysis/runner_action.go:105 +0x2a
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc000bc6a50, 0x4de5b4a, 0x8, 0xc00240c770)
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/timeutils/stopwatch.go:111 +0x4d
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc001942000)
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/goanalysis/runner_action.go:104 +0x91
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc0009cec50, 0xc001942000)
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0x65
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x316
WARN [runner] Can't run linter gocritic: gocritic: gocritic: package "mcpp" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is int64, not int
INFO [runner] processing took 8.051µs with stages: max_same_issues: 3.16µs, nolint: 2.341µs, skip_dirs: 525ns, max_from_linter: 257ns, source_code: 153ns, cgo: 149ns, autogenerated_exclude: 144ns, uniq_by_line: 143ns, path_prettifier: 141ns, identifier_marker: 141ns, filename_unadjuster: 137ns, skip_files: 137ns, diff: 135ns, sort_results: 81ns, severity-rules: 73ns, path_shortener: 71ns, max_per_file_from_linter: 67ns, exclude-rules: 67ns, exclude: 66ns, path_prefixer: 63ns
INFO [runner] linters took 2.505689348s with stages: gocritic: 2.505533558s
INFO File cache stats: 0 entries of total size 0B
INFO Memory: 63 samples, avg is 136.8MB, max is 274.1MB
INFO Execution took 6.176502549s

Panic w/ sample JSON config:

golangci-lint run -v --config .golangci.json
INFO [config_reader] Used config file .golangci.json
INFO [lintersdb] Active 1 linters: [gocritic]
INFO [loader] Go packages loading at mode 575 (deps|files|imports|name|types_sizes|compiled_files|exports_file) took 3.368260444s
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 88.362515ms
INFO [linters context/goanalysis] analyzers took 0s with no stages
ERRO [runner] Panic: gocritic: package "mcpp" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is float64, not int: goroutine 10683 [running]:
runtime/debug.Stack(0x4e8b00f, 0x3c, 0xc003255708)
        /Users/hardmanc/sdk/go1.16.5/src/runtime/debug/stack.go:24 +0x9f
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1(0xc0021da000)
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/goanalysis/runner_action.go:101 +0x1be
panic(0x4c899a0, 0xc003cbac00)
        /Users/hardmanc/sdk/go1.16.5/src/runtime/panic.go:965 +0x1b9
github.com/go-critic/go-critic/framework/linter.CheckerParams.Int(...)
        /Users/hardmanc/go/pkg/mod/github.com/go-critic/go-critic@v0.5.6/framework/linter/lintpack.go:54
github.com/go-critic/go-critic/checkers.init.36.func1(0xc000414688, 0xc000414688, 0xc001ecdc90, 0x9f0000c003255a20, 0x411159d)
        /Users/hardmanc/go/pkg/mod/github.com/go-critic/go-critic@v0.5.6/checkers/hugeParam_checker.go:27 +0x145
github.com/go-critic/go-critic/framework/linter.addChecker.func2(0xc0044bc640, 0xc000198a50, 0x4df5177, 0x9)
        /Users/hardmanc/go/pkg/mod/github.com/go-critic/go-critic@v0.5.6/framework/linter/checkers_db.go:79 +0xdc
github.com/go-critic/go-critic/framework/linter.newChecker(0xc0044bc640, 0xc004aa2e10, 0x0, 0x0, 0xc0008398e8)
        /Users/hardmanc/go/pkg/mod/github.com/go-critic/go-critic@v0.5.6/framework/linter/checkers_db.go:92 +0x71
github.com/go-critic/go-critic/framework/linter.NewChecker(...)
        /Users/hardmanc/go/pkg/mod/github.com/go-critic/go-critic@v0.5.6/framework/linter/lintpack.go:144
github.com/golangci/golangci-lint/pkg/golinters.buildEnabledCheckers(0xc0010563f0, 0xc0044bc640, 0x0, 0x0, 0x0, 0x0, 0x0)
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/gocritic.go:127 +0x185
github.com/golangci/golangci-lint/pkg/golinters.NewGocritic.func1.1(0xc0005b5790, 0x1200c76a7, 0x57a7d40, 0xc00101a080, 0x2)
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/gocritic.go:44 +0x11f
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc0021da000)
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/goanalysis/runner_action.go:187 +0x9f2
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/goanalysis/runner_action.go:105 +0x2a
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc000743770, 0x4de5b4a, 0x8, 0xc003b8f770)
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/timeutils/stopwatch.go:111 +0x4d
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc0021da000)
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/goanalysis/runner_action.go:104 +0x91
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc001ecdae0, 0xc0021da000)
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0x65
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze
        /Users/hardmanc/go/pkg/mod/github.com/golangci/golangci-lint@v1.42.0/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x316
WARN [runner] Can't run linter gocritic: gocritic: gocritic: package "mcpp" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is float64, not int
INFO [runner] processing took 21.635µs with stages: nolint: 15.641µs, max_same_issues: 2.622µs, skip_dirs: 785ns, max_from_linter: 264ns, cgo: 255ns, filename_unadjuster: 246ns, source_code: 193ns, diff: 186ns, path_prettifier: 179ns, path_shortener: 171ns, skip_files: 170ns, autogenerated_exclude: 155ns, uniq_by_line: 145ns, identifier_marker: 143ns, sort_results: 113ns, path_prefixer: 86ns, severity-rules: 79ns, exclude: 71ns, max_per_file_from_linter: 68ns, exclude-rules: 63ns
INFO [runner] linters took 2.235113172s with stages: gocritic: 2.231650197s
INFO File cache stats: 0 entries of total size 0B
INFO Memory: 59 samples, avg is 126.6MB, max is 273.2MB
INFO Execution took 5.798350572s

Code example or link to a public repository

Panic can be observed on absolute minimum main.go:

package main

func main() {
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions