Comments (8)
@mprimeaux, I'm working on it. Just checking for a nil AST isn't quite enough. A better fix will handle a lack of AST by using the descriptor in the parse result to recursively crawl through imports.
I also realized that the InferImportPaths
never had a proper test, which is why this bug has been lurking for so long (certainly broken in v1.15.0). In adding a test, I see a few other issues (unrelated to the panic you found), and am fixing those, too. So the next release will fix the panic as well as improve the behavior of the InferImportPaths
flag.
from protoreflect.
As an update, I pulled down the protoreflect
code and wrote a new test using the same failing .proto
file and it parsed it just fine; no SIGSEGV panic.
After further debugging, I was able to trip the exact panic by setting InferImportPaths
to true
on the protoparse.Parser
. I'll update this issue once I've identified the cause.
Also, I updated the related grpcurl
issue since the currently workaround is to specify the -import-path
option.
from protoreflect.
I believe the fix is to the function parseToProtosRecursive
in parser.go
here by adding a nil
check for astRoot
.
func parseToProtoRecursive(res protocompile.Resolver, filename string, rep *reporter.Handler, srcPosAddr *SourcePos, results map[string]parser.Result) {
if _, ok := results[filename]; ok {
// already processed this one
return
}
results[filename] = nil // placeholder entry
astRoot, parseResult, _ := parseToAST(res, filename, rep)
if rep.ReporterError() != nil {
return
}
if parseResult == nil {
parseResult, _ = parser.ResultFromAST(astRoot, true, rep)
if rep.ReporterError() != nil {
return
}
}
results[filename] = parseResult
+ if astRoot == nil {
+ return
+ }
for _, decl := range astRoot.Decls {
imp, ok := decl.(*ast2.ImportNode)
if !ok {
continue
}
func() {
orig := *srcPosAddr
*srcPosAddr = astRoot.NodeInfo(imp.Name).Start()
defer func() {
*srcPosAddr = orig
}()
parseToProtoRecursive(res, imp.Name.AsString(), rep, srcPosAddr, results)
}()
if rep.ReporterError() != nil {
return
}
}
}
from protoreflect.
Looks like the panic is triggered when an import line is encountered in the .proto
file. For example,
syntax = "proto3";
import "google/protobuf/struct.proto";
To reproduce this, I modified the existing test named TestBuilder_PreserveAllCommentsAfterBuild
in builder_test.go
that was passing before with the above import
and now it fails with the exact panic.
The decl.(*ast2.ImportNode)
cast here assumes the import is for a local file and doesn't seem to handle the Google protobuf types.
After I add the nil check as in my previous comment the failing test passes.
I'll leave this here until @jhump or another maintainer has an opportunity to review. I still think the nil
check above might be a viable option.
from protoreflect.
@mprimeaux are you willing to submit a PR for the issue as you already do have the code ready!? We are hitting the same issue in Telegraf...
from protoreflect.
@srebhan Sure. I'll submit a PR shortly.
from protoreflect.
@jhump Sounds great and thanks for your help. Shall I just cancel my PR since you're got a handle on it?
from protoreflect.
Fixed in #575.
from protoreflect.
Related Issues (20)
- Breaking changes in the protocompile/ast dependency
- EnumBuilder panics if it contains EnumValue with explicitly set Number HOT 1
- might not be bug: false duplication report due to use of relative path instead of absolute path HOT 6
- Protoreflect doesn't fall back to to v1alpha when a gRPC unimplemented response is returned HOT 1
- String escaping in protoprint is wrong HOT 1
- First enum value must be 0 in proto3 [protoprint] HOT 2
- missing `{}` after printing option HOT 5
- Upgrade protocompile to v0.7.0 HOT 3
- go build error HOT 3
- Regression upgrading from v1.14.1 to v1.15.4: extensions are resolved recursively instead of non-recursively HOT 1
- Regression upgrading from v1.14.1 to v1.15.4: absolute paths no longer accepted by parser.ParseFilesButDoNotLink HOT 3
- Regression upgrading from v1.14.1 to v1.15.4: new mustBeSource constraint/check HOT 5
- Stub structure and Methods will relay on protobuf API V2 HOT 15
- Fail to compile proto file HOT 2
- Tests broken with google.golang.org/protobuf v1.33.0
- If there are messages nested in the proto file, the numbers will be recognised as strings HOT 2
- invalid memory address or nil pointer dereference HOT 5
- will return Symbol not found when the proto file has enum definition HOT 1
- Is there a way to UseProtoNames? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protoreflect.