Skip to content

infra/conf/v2jsonpb: return nil for unknown field names - #3840

Draft
somaz94 wants to merge 1 commit into
v2fly:masterfrom
somaz94:fix/v2jsonpb-unknown-field
Draft

somaz94 wants to merge 1 commit into
v2fly:masterfrom
somaz94:fix/v2jsonpb-unknown-field

Conversation

@somaz94

@somaz94 somaz94 commented Oct 7, 2026

Copy link
Copy Markdown

Loading a config through the v2jsonpb loader panics with a nil pointer dereference as soon as it meets a field name the message does not define. When the config comes from stdin, v2ray tries every loader in turn and v2jsonpb panics before the others get a chance, so echo '{ "status": {} }' | v2ray test crashes instead of falling through to the next format. This is what #3598 reports.

ByJSONName and ByTextName on V2JsonProtobufFollowerFields wrap the inner lookup in V2JsonProtobufFollowerFieldDescriptor even when it finds nothing, so protojson gets a non-nil descriptor holding nil. protojson only reports an unknown field, and only retries with the proto field name, when the lookup returns nil, so it calls fd.Number() on the empty wrapper instead. Snake case keys such as receiver_settings hit the same panic for the same reason.

Both methods now return nil when the inner lookup finds nothing. The new TestLoadFieldNames covers a JSON name, a proto name, and an unknown field at the top level, in a list element and inside an Any value.

Validation: the new test panics without the change and passes with it, on go1.27.1 and go1.26.1. The stdin command above panicked before and prints Configuration OK. after. golangci-lint with .github/linters/.golangci.yml reports 0 issues, and go mod tidy leaves go.mod and go.sum unchanged. go test ./... passes except TestServiceSubscribeRoutingStats in app/router/command, which failed once in the full run, passes 10 out of 10 runs on its own with and without this change, and does not depend on v2jsonpb.

Fixes #3598

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v2ray 通过 stdin 获取任意有效配置时会崩溃

1 participant