Skip to content

fix(encoding/form): avoid nil pointer panic on null well-known type value - #3879

Open
jaideeppyne wants to merge 3 commits into
go-kratos:mainfrom
jaideeppyne:fix/form-null-wellknown-panic
Open

jaideeppyne wants to merge 3 commits into
go-kratos:mainfrom
jaideeppyne:fix/form-null-wellknown-panic

Conversation

@jaideeppyne

Copy link
Copy Markdown

What

Decoding a query/form value of null for a google.protobuf.Timestamp or google.protobuf.Duration field panics the server with a nil pointer dereference.

Why

parseMessage special-cases the "null" literal for Timestamp/Duration by break-ing out of the type switch without assigning msg, then unconditionally calls msg.ProtoReflect(). Since msg is a nil proto.Message, this is a nil pointer dereference (proto_decode.go:330). Because the value is attacker-controllable via the URL query string, this is a remotely triggerable crash.

Repro

Any HTTP request proto with a Timestamp/Duration field, called with ?timestamp=null → SIGSEGV in DecodeValues.

Fix

Return an invalid protoreflect.Value for the null case and skip assignment in populateField/populateRepeatedField/populateMapField, so a null literal leaves the field unset — matching protojson semantics for a JSON null message field. Adds a regression test (TestDecodeValues_NullWellKnownType) that panics before the change and passes after. gofmt/go vet clean.

…alue

parseMessage handles a "null" literal for google.protobuf.Timestamp and
google.protobuf.Duration by breaking out of the switch without assigning
msg, then unconditionally calls msg.ProtoReflect(). Because msg is a nil
proto.Message interface, decoding a query/form value such as
`timestamp=null` panics with a nil pointer dereference, crashing the
request (and any others handled before recovery middleware runs).

Return an invalid protoreflect.Value for the null case and skip assignment
in populateField/populateRepeatedField/populateMapField, so a null literal
leaves the message field unset, matching protojson semantics.

Adds a regression test covering null Timestamp/Duration values.
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Aug 25, 2026
@jaideeppyne

Copy link
Copy Markdown
Author

CI follow-up

The non-english-comments-check job fails before scanning source: actions/checkout@v6 refuses to check out fork code in a pull_request_target workflow. Its fallback comment also fails with a workflow-token 403.

This is a base-repository workflow issue, not a detected non-English comment in this patch. I have left the safety protection enabled and have not added an unsafe-checkout override. Could a maintainer run an appropriately isolated check or adjust the workflow?

@xue-ding-e

Copy link
Copy Markdown

AI-assisted test follow-up: your regression covers singular Timestamp/Duration fields. I prepared a test-only supplement for the separate list/map assignment guards: ba247439, based directly on your 7da5257b.

The four cases (Timestamp/Duration × repeated/map) check that null values are skipped while valid neighboring values survive. In an isolated, offline Go 1.26.10 harness using the actual decoder source:

  • Current main dd0fb7df: all four fail with nil-pointer panics.
  • Your 7da5257b: all four pass.

This is not full-package testing or hosted CI. No product fix is duplicated; the commit only adds one test file and can be cherry-picked into this PR if useful.

xue-ding-e and others added 2 commits October 29, 2026 05:05
Complement the singular-field regression in upstream PR go-kratos#3879 with
Timestamp and Duration list/map cases. Verify null values are skipped
without losing neighboring non-null values.

This test-only candidate depends on the existing fix in go-kratos#3879.
@jaideeppyne

Copy link
Copy Markdown
Author

The test-only supplement from @xue-ding-e is included in 0aface0, preserving its author credit. It covers null values in repeated and map fields for both protobuf Timestamp and Duration, while checking that valid neighboring values survive. The descriptor formatting is corrected in a5f7be3.

Validation: Go 1.25 and 1.26 verification passed go test -race -count=10 ./encoding/form, go test ./encoding/..., and go vet ./encoding/.... The fork lint run also passed.

The upstream non-English-title workflow still requires maintainer handling; its protected checkout restriction has been preserved.

This branch has not been deployed

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

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants