Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MaxMessageLength behavior #32

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions wire/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 255
// The official implementation of adb imposes an undocumented 1-megabyte limit
// on payload size.
MaxPayloadSize = 1024 * 1024
)

/*
Expand Down
7 changes: 1 addition & 6 deletions wire/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion wire/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) > MaxPayloadSize- 4 {
return errors.AssertionErrorf("message length exceeds maximum: %d", len(msg))
}

Expand Down