Skip to content

Commit dc23b21

Browse files
committed
fix(jsonrpc): avoid corrupting the offset maximum reported by 'rpc.discover'
- Changed Service.discoverSpec from any to json.RawMessage. - Retained json.Unmarshal, validating and copying the embedded JSON without converting numbers to float64. - Added a regression test asserting rpc.discover returns the exact literal 9223372036854775807.
1 parent 20ca140 commit dc23b21

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

internal/jsonrpc/batchcalls_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ func TestJSONRPCMalformedObjectReturnsJSONContentType(t *testing.T) {
166166
requireRPCError(t, decodeRPCResponse(t, rr.Body.Bytes()), nil, JSONRPC_PARSE_ERROR)
167167
}
168168

169+
func TestJSONRPCDiscoverPreservesLargeIntegerLiterals(t *testing.T) {
170+
s := newBatchTestService()
171+
data, err := discoverSpec.ReadFile("jsonrpc-discover.json")
172+
require.NoError(t, err)
173+
require.NoError(t, json.Unmarshal(data, &s.discoverSpec))
174+
175+
rr := serveRPC(t, s, []byte(`{"jsonrpc":"2.0","method":"rpc.discover","id":1}`))
176+
177+
require.Equal(t, http.StatusOK, rr.Code)
178+
require.Contains(t, rr.Body.String(), `"maximum":9223372036854775807`)
179+
}
180+
169181
func TestJSONRPCBatchMalformedElementDoesNotPoisonValidSiblings(t *testing.T) {
170182
s := newBatchTestService()
171183
body := []byte(`[

internal/jsonrpc/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type Service struct {
4242
// overridden in tests so Serve() can be exercised without real sockets.
4343
listen func(network, address string) (net.Listener, error)
4444
// OpenAPI description for JSON-RPC API loaded from 'jsonrpc-discover.json' file
45-
discoverSpec any
45+
discoverSpec json.RawMessage
4646
handlers dispatchTable
4747
// dispatchTimeout expires requests early enough to serialize a complete
4848
// timeout response before the HTTP server's write deadline.

0 commit comments

Comments
 (0)