返回 DeepSeek-Reasonix
jsonrpc_framecap_test.go
根目录 / internal / lsp / jsonrpc_framecap_test.go
1 package lsp
2
3 import (
4 "bufio"
5 "strings"
6 "testing"
7 )
8
9 // TestReadFrameRejectsOversizeContentLength proves a corrupt or hostile
10 // Content-Length is rejected before the body is allocated — a gigabyte length
11 // must not trigger a gigabyte make([]byte). The reader holds no body, so the only
12 // way this returns without hanging or OOMing is the cap check.
13 func TestReadFrameRejectsOversizeContentLength(t *testing.T) {
14 r := bufio.NewReader(strings.NewReader("Content-Length: 9999999999999\r\n\r\n"))
15 if _, err := readFrame(r); err == nil {
16 t.Fatal("oversize Content-Length should be rejected")
17 } else if !strings.Contains(err.Error(), "frame cap") {
18 t.Fatalf("want a frame-cap error, got %v", err)
19 }
20 }
21
21 lines GO