From 27fce27fb80ed8ee48ce002897247cf41d3393f7 Mon Sep 17 00:00:00 2001 From: Quang Le Date: Tue, 24 Nov 2020 15:41:31 +0700 Subject: [PATCH 1/4] Fix typos --- wire/scanner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wire/scanner.go b/wire/scanner.go index 58f6066..5cfd567 100644 --- a/wire/scanner.go +++ b/wire/scanner.go @@ -9,7 +9,7 @@ import ( "github.com/zach-klippenstein/goadb/internal/errors" ) -// TODO(zach): All EOF errors returned from networoking calls should use ConnectionResetError. +// TODO(zach): All EOF errors returned from networking calls should use ConnectionResetError. // StatusCodes are returned by the server. If the code indicates failure, the // next message will be the error. From 9c93331eb68a8343333a0906dfd4cbff62f57f1c Mon Sep 17 00:00:00 2001 From: Quang Le Date: Tue, 24 Nov 2020 15:50:14 +0700 Subject: [PATCH 2/4] Remove MaxMessageLength checks when parse messages returned from adb server --- wire/scanner.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/wire/scanner.go b/wire/scanner.go index 5cfd567..94565bc 100644 --- a/wire/scanner.go +++ b/wire/scanner.go @@ -163,11 +163,6 @@ func readHexLength(r io.Reader) (int, error) { return 0, errors.WrapErrorf(err, errors.NetworkError, "could not parse hex length %v", lengthHex) } - // Clip the length to 255, as per the Google implementation. - if length > MaxMessageLength { - length = MaxMessageLength - } - return int(length), nil } From 4ca8f454a133bcf5b2a000404e4aa77632a9fd17 Mon Sep 17 00:00:00 2001 From: Quang Le Date: Tue, 24 Nov 2020 16:32:23 +0700 Subject: [PATCH 3/4] Update MaxMessageLength to reflect adb implementation --- wire/conn.go | 2 +- wire/sender.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wire/conn.go b/wire/conn.go index 2940bdb..55c7ecc 100644 --- a/wire/conn.go +++ b/wire/conn.go @@ -5,7 +5,7 @@ import "github.com/zach-klippenstein/goadb/internal/errors" const ( // The official implementation of adb imposes an undocumented 255-byte limit // on messages. - MaxMessageLength = 255 + MaxMessageLength = 1024 * 1024 ) /* diff --git a/wire/sender.go b/wire/sender.go index cb40634..3193dce 100644 --- a/wire/sender.go +++ b/wire/sender.go @@ -29,7 +29,7 @@ func SendMessageString(s Sender, msg string) error { } func (s *realSender) SendMessage(msg []byte) error { - if len(msg) > MaxMessageLength { + if len(msg) > MaxMessageLength - 4 { return errors.AssertionErrorf("message length exceeds maximum: %d", len(msg)) } From a46e61a9ffa47f9c100019c4b1361b5fd79e2e8b Mon Sep 17 00:00:00 2001 From: Quang Le Date: Tue, 8 Dec 2020 13:13:53 +0700 Subject: [PATCH 4/4] Rename MaxMessageLength to MaxPayloadSize to reflect adb's implementation --- wire/conn.go | 6 +++--- wire/sender.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/wire/conn.go b/wire/conn.go index 55c7ecc..0af8890 100644 --- a/wire/conn.go +++ b/wire/conn.go @@ -3,9 +3,9 @@ package wire import "github.com/zach-klippenstein/goadb/internal/errors" const ( - // The official implementation of adb imposes an undocumented 255-byte limit - // on messages. - MaxMessageLength = 1024 * 1024 + // The official implementation of adb imposes an undocumented 1-megabyte limit + // on payload size. + MaxPayloadSize = 1024 * 1024 ) /* diff --git a/wire/sender.go b/wire/sender.go index 3193dce..b8d3a32 100644 --- a/wire/sender.go +++ b/wire/sender.go @@ -29,7 +29,7 @@ func SendMessageString(s Sender, msg string) error { } func (s *realSender) SendMessage(msg []byte) error { - if len(msg) > MaxMessageLength - 4 { + if len(msg) > MaxPayloadSize- 4 { return errors.AssertionErrorf("message length exceeds maximum: %d", len(msg)) }