Repository navigation
Parse rebar.config deps and plugins and OTP application metadata from *.app.src - #174
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
andrew
left a comment
There was a problem hiding this comment.
The term reader in internal/rebar/term.go recurses through term, sequence, list, binary and mapTerm with no depth limit, so the nesting depth of the input sets the depth of the Go stack. A rebar.config or *.app.src made of a long enough run of [ would exhaust the stack, which in Go is a fatal error that bypasses recover and exits the calling process. These files come from scanned repositories, so add a depth counter to termReader that returns a parse error past a fixed limit, with a test for it. maxNpmOverrideDepth in internal/npm/overrides.go is the equivalent limit for npm overrides. The {pkg, Name} renames, the rebar2 version regex and the profile scopes all match how rebar3 reads these files, so the depth limit is the only change needed.
|
Thanks. termReader now tracks depth in term(), which every tuple, list, binary and map goes through. Past maxTermDepth (100) it returns a parse error. I went higher than npm's 32 because exceeding the limit here fails the whole file rather than skipping a subtree, and real rebar configs nest only a few levels. Tests check that 100 levels parse, 101 fail, and a million { or [ as well as deeply nested binaries and maps all fail with the depth error. I added a line about the limit to the README too. |
Part of #77 (the Erlang and Elixir item).
Summary
Adds two
hexmanifest parsers ininternal/rebar, next to the existingrebar.lockparser, on top of a small Erlang term reader.Erlang term reader
internal/rebar/term.goreads dot-terminated terms the wayfile:consult/1does: tuples, lists, quoted and bare atoms, strings (adjacent literals joined), binaries (string segments kept, size and type specifiers skipped), integers, floats, based integers such as16#ff, character literals, maps, list tails and%comments. Anything else, such as a?MACRO, is aParseErrorwith a line number, sincefile:consult/1rejects it too.rebar.config
jsxName: jsx, no version{cowboy, "2.10.0"},{lager, "~> 3.9"}{jiffy, "1.1.1", {pkg, jiffy_fork}}Name: jiffy_fork(the Hex package), locationdeps/jiffy{recon, {git, URL, {tag, "2.5.3"}}}gitsource withTag;branchandrefgo toBranchandRef{app, {git_subdir, URL, Spec, "dir"}}gitsource with the directory inRel{app, {hg, URL, Spec}}urlsource{legacy, ".*", {git, URL, "HEAD"}}(rebar2)Refdepsareruntime.depsinsideprofilesaretestfor thetestprofile,runtimeforprodanddevelopmentfor any other profile, underprofiles/<profile>/deps/<app>.pluginsandproject_pluginsarebuildwherever they appear.Cargo.tomlgit dependencies do.*.app.src
NameandVersioncome from{application, Name, [...]}andvsn. Avsnofgitor{cmd, ...}is not a version and is left empty.licensesfillsLicenses,descriptionfillsMetadata.Descriptionand eachlinksentry is aMetadata.Linksitem with its own label.applicationsandincluded_applicationsare versionlessruntimedependencies. Entries inoptional_applications(which OTP 24 also requires inapplications) are reported once withoptionalscope.kernel,stdlib,crypto,ssl,logger,elixirand so on) are skipped since they are not Hex packages.Tests
internal/rebar/term_test.gocovers each term form and the syntax errors.internal/rebar/config_test.gocovers every dependency form in the fixture with scopes and locations, malformed entries, nested profiles and invalid input.internal/rebar/appsrc_test.gocovers the fixture with metadata, licenses and optional applications,gitand{cmd, ...}versions, built-in applications, non-application terms and invalid input.rebar_manifests_test.gogoes throughParse, checking PURLs for renamed packages and dependencies.TestIdentifyFiles,TestParseAllEcosystems,TestParseNameandTestParseDeclaredLicenses.testdata/rebar/rebar.configandtestdata/rebar/myapp.app.src.go build ./...,go vet ./...,go test ./...andgolangci-lint run ./...all pass.