aboutsummaryrefslogtreecommitdiff
path: root/src/compress
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2022-09-13 22:20:06 -0700
committerGopher Robot <gobot@golang.org>2023-02-27 18:51:27 +0000
commit9a199d42dab00636f503c47ac4e02595765373f2 (patch)
treea19b9d2db1cedfac5f2c2a5fc8209fcb9f8f2275 /src/compress
parent8538477d58b97ad7f5c91c9c5b7007404f2a6dac (diff)
downloadgo-9a199d42dab00636f503c47ac4e02595765373f2.tar.gz
go-9a199d42dab00636f503c47ac4e02595765373f2.zip
compress/zlib: use binary.BigEndian consistently
One major reason to avoid binary.BigEndian is because the binary package includes a transitive dependency on reflect. See #54097. Given that writer.go already depends on the binary package, embrace use of it consistently where sensible. We should either embrace use of binary or fully avoid it. Change-Id: I5f2d27d0ed8cab5ac54be02362c7d33276dd4b9a Reviewed-on: https://go-review.googlesource.com/c/go/+/452176 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Auto-Submit: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/compress')
-rw-r--r--src/compress/zlib/reader.go7
-rw-r--r--src/compress/zlib/writer.go2
2 files changed, 5 insertions, 4 deletions
diff --git a/src/compress/zlib/reader.go b/src/compress/zlib/reader.go
index 343a18bf68..10954eaad7 100644
--- a/src/compress/zlib/reader.go
+++ b/src/compress/zlib/reader.go
@@ -26,6 +26,7 @@ package zlib
import (
"bufio"
"compress/flate"
+ "encoding/binary"
"errors"
"hash"
"hash/adler32"
@@ -110,7 +111,7 @@ func (z *reader) Read(p []byte) (int, error) {
return n, z.err
}
// ZLIB (RFC 1950) is big-endian, unlike GZIP (RFC 1952).
- checksum := uint32(z.scratch[0])<<24 | uint32(z.scratch[1])<<16 | uint32(z.scratch[2])<<8 | uint32(z.scratch[3])
+ checksum := binary.BigEndian.Uint32(z.scratch[:4])
if checksum != z.digest.Sum32() {
z.err = ErrChecksum
return n, z.err
@@ -145,7 +146,7 @@ func (z *reader) Reset(r io.Reader, dict []byte) error {
}
return z.err
}
- h := uint(z.scratch[0])<<8 | uint(z.scratch[1])
+ h := binary.BigEndian.Uint16(z.scratch[:2])
if (z.scratch[0]&0x0f != zlibDeflate) || (z.scratch[0]>>4 > zlibMaxWindow) || (h%31 != 0) {
z.err = ErrHeader
return z.err
@@ -159,7 +160,7 @@ func (z *reader) Reset(r io.Reader, dict []byte) error {
}
return z.err
}
- checksum := uint32(z.scratch[0])<<24 | uint32(z.scratch[1])<<16 | uint32(z.scratch[2])<<8 | uint32(z.scratch[3])
+ checksum := binary.BigEndian.Uint32(z.scratch[:4])
if checksum != adler32.Checksum(dict) {
z.err = ErrDictionary
return z.err
diff --git a/src/compress/zlib/writer.go b/src/compress/zlib/writer.go
index 9986e3834d..c65e80f742 100644
--- a/src/compress/zlib/writer.go
+++ b/src/compress/zlib/writer.go
@@ -115,7 +115,7 @@ func (z *Writer) writeHeader() (err error) {
if z.dict != nil {
z.scratch[1] |= 1 << 5
}
- z.scratch[1] += uint8(31 - (uint16(z.scratch[0])<<8+uint16(z.scratch[1]))%31)
+ z.scratch[1] += uint8(31 - binary.BigEndian.Uint16(z.scratch[:2])%31)
if _, err = z.w.Write(z.scratch[0:2]); err != nil {
return err
}