Repository navigation
fix(encoding/form): avoid nil pointer panic on null well-known type value - #3879
jaideeppyne wants to merge 3 commits into
Conversation
…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.
CI follow-upThe 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? |
|
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 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:
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. |
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.
Includes-AI-Code: true
|
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 Validation: Go 1.25 and 1.26 verification passed The upstream non-English-title workflow still requires maintainer handling; its protected checkout restriction has been preserved. |
What
Decoding a query/form value of
nullfor agoogle.protobuf.Timestamporgoogle.protobuf.Durationfield panics the server with a nil pointer dereference.Why
parseMessagespecial-cases the"null"literal for Timestamp/Duration bybreak-ing out of the type switch without assigningmsg, then unconditionally callsmsg.ProtoReflect(). Sincemsgis a nilproto.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/Durationfield, called with?timestamp=null→SIGSEGVinDecodeValues.Fix
Return an invalid
protoreflect.Valuefor the null case and skip assignment inpopulateField/populateRepeatedField/populateMapField, so anullliteral leaves the field unset — matching protojson semantics for a JSONnullmessage field. Adds a regression test (TestDecodeValues_NullWellKnownType) that panics before the change and passes after.gofmt/go vetclean.