[tor-commits] [meek/master] Make the native extension work with GOARCH=386.

dcf at torproject.org dcf at torproject.org
Wed Aug 28 05:59:18 UTC 2019


commit 663c0c69f76c0fc86ea06a56efc0719bc3d7c4ab
Author: David Fifield <david at bamsoftware.com>
Date:   Thu Feb 21 10:49:50 2019 -0700

    Make the native extension work with GOARCH=386.
---
 webextension/native/endian_386.go |  8 ++++++++
 webextension/native/main.go       | 10 ++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/webextension/native/endian_386.go b/webextension/native/endian_386.go
new file mode 100644
index 0000000..6a1e44e
--- /dev/null
+++ b/webextension/native/endian_386.go
@@ -0,0 +1,8 @@
+// The WebExtension browser–app protocol uses native-endian length prefixes :/
+// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging#App_side
+
+package main
+
+import "encoding/binary"
+
+var NativeEndian = binary.LittleEndian
diff --git a/webextension/native/main.go b/webextension/native/main.go
index 5d071b3..9424715 100644
--- a/webextension/native/main.go
+++ b/webextension/native/main.go
@@ -138,8 +138,11 @@ func writeResponseSpec(w io.Writer, spec *responseSpec) error {
 		panic(err)
 	}
 
+	// len returns int, which is specified to be either 32 or 64 bits, so it
+	// will never be truncated when converting to uint64.
+	// https://golang.org/ref/spec#Numeric_types
 	length := len(encodedSpec)
-	if length > math.MaxUint32 {
+	if uint64(length) > math.MaxUint32 {
 		return fmt.Errorf("response spec is too long to represent: %d", length)
 	}
 	err = binary.Write(w, binary.BigEndian, uint32(length))
@@ -177,8 +180,11 @@ func recvWebExtensionMessage(r io.Reader) ([]byte, error) {
 // Send a WebExtension message.
 // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging#App_side
 func sendWebExtensionMessage(w io.Writer, message []byte) error {
+	// len returns int, which is specified to be either 32 or 64 bits, so it
+	// will never be truncated when converting to uint64.
+	// https://golang.org/ref/spec#Numeric_types
 	length := len(message)
-	if length > math.MaxUint32 {
+	if uint64(length) > math.MaxUint32 {
 		return fmt.Errorf("WebExtension message is too long to represent: %d", length)
 	}
 	err := binary.Write(w, NativeEndian, uint32(length))





More information about the tor-commits mailing list