1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
From: Shengjing Zhu <zhsj@debian.org>
Date: Sun, 10 Jan 2021 23:08:56 +0800
Subject: Fix int overflow on 32bit
Forwarded: https://github.com/google/go-dap/pull/52
---
io.go | 4 ++--
io_test.go | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/io.go b/io.go
index 5b85851..87125ef 100644
--- a/io.go
+++ b/io.go
@@ -95,7 +95,7 @@ func ReadBaseMessage(r *bufio.Reader) ([]byte, error) {
// and required:
// Content-Length: [0-9]+\r\n\r\n
// Extracts and returns the content length.
-func readContentLengthHeader(r *bufio.Reader) (contentLength int, err error) {
+func readContentLengthHeader(r *bufio.Reader) (contentLength int64, err error) {
// Look for <some header>\r\n\r\n
headerWithCr, err := r.ReadString('\r')
if err != nil {
@@ -115,7 +115,7 @@ func readContentLengthHeader(r *bufio.Reader) (contentLength int, err error) {
if len(headerAndLength) < 2 {
return 0, ErrHeaderNotContentLength
}
- return strconv.Atoi(headerAndLength[1])
+ return strconv.ParseInt(headerAndLength[1], 10, 64)
}
// WriteProtocolMessage encodes message and writes it to w.
diff --git a/io_test.go b/io_test.go
index 0c1a0fe..8c1b01e 100644
--- a/io_test.go
+++ b/io_test.go
@@ -90,7 +90,7 @@ func Test_readContentLengthHeader(t *testing.T) {
tests := []struct {
input string
wantBytesLeft string // Bytes left in the reader after header reading
- wantLen int // Extracted content length value
+ wantLen int64 // Extracted content length value
wantErr error
}{
{"", "", 0, io.EOF},
|