[go] compress/zlib: tighten header CINFO check

17 views
Skip to first unread message

Nigel Tao (Gerrit)

unread,
Mar 24, 2022, 7:39:04 PM3/24/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Nigel Tao has uploaded this change for review.

View Change

compress/zlib: tighten header CINFO check

RFC 1950 section 2.2 "Data format" says "CINFO (Compression info)... For
CM = 8... Values of CINFO above 7 are not allowed".

Change-Id: Ibbc1213125c7dc045f09901ee7746660e90b5fcd
---
M src/compress/zlib/reader.go
M src/compress/zlib/reader_test.go
2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/compress/zlib/reader.go b/src/compress/zlib/reader.go
index a195b38..3bbd873 100644
--- a/src/compress/zlib/reader.go
+++ b/src/compress/zlib/reader.go
@@ -32,7 +32,10 @@
"io"
)

-const zlibDeflate = 8
+const (
+ zlibDeflate = 8
+ zlibMaxWindow = 7
+)

var (
// ErrChecksum is returned when reading ZLIB data that has an invalid checksum.
@@ -143,7 +146,7 @@
return z.err
}
h := uint(z.scratch[0])<<8 | uint(z.scratch[1])
- if (z.scratch[0]&0x0f != zlibDeflate) || (h%31 != 0) {
+ if (z.scratch[0]>>4 > zlibMaxWindow) || (z.scratch[0]&0x0f != zlibDeflate) || (h%31 != 0) {
z.err = ErrHeader
return z.err
}
diff --git a/src/compress/zlib/reader_test.go b/src/compress/zlib/reader_test.go
index 70e33ba..20cec69 100644
--- a/src/compress/zlib/reader_test.go
+++ b/src/compress/zlib/reader_test.go
@@ -65,7 +65,14 @@
nil,
},
{
- "bad header",
+ "bad header (CINFO)",
+ "",
+ []byte{0x88, 0x98, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01},
+ nil,
+ ErrHeader,
+ },
+ {
+ "bad header (FCHECK)",
"",
[]byte{0x78, 0x9f, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01},
nil,

To view, visit change 395734. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ibbc1213125c7dc045f09901ee7746660e90b5fcd
Gerrit-Change-Number: 395734
Gerrit-PatchSet: 1
Gerrit-Owner: Nigel Tao <nige...@golang.org>
Gerrit-MessageType: newchange

Matthew Dempsky (Gerrit)

unread,
Mar 24, 2022, 8:12:16 PM3/24/22
to Nigel Tao, goph...@pubsubhelper.golang.org, Joseph Tsai, Gopher Robot, golang-co...@googlegroups.com

Attention is currently required from: Joseph Tsai, Nigel Tao.

Patch set 1:Run-TryBot +1Code-Review +2

View Change

1 comment:

  • File src/compress/zlib/reader.go:

    • Patch Set #1, Line 149: (z.scratch[0]&0x0f != zlibDeflate)

      nit: keep the CM==zlibDeflate check first?

      I know it doesn't actually matter right now, but since CINFO is only conditionally defined based on CM, it seems appropriate to validate CM first.

To view, visit change 395734. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ibbc1213125c7dc045f09901ee7746660e90b5fcd
Gerrit-Change-Number: 395734
Gerrit-PatchSet: 1
Gerrit-Owner: Nigel Tao <nige...@golang.org>
Gerrit-Reviewer: Joseph Tsai <joe...@digital-static.net>
Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Joseph Tsai <joe...@digital-static.net>
Gerrit-Attention: Nigel Tao <nige...@golang.org>
Gerrit-Comment-Date: Fri, 25 Mar 2022 00:12:11 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

Nigel Tao (Gerrit)

unread,
Mar 29, 2022, 10:14:13 PM3/29/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Joseph Tsai, Nigel Tao.

Nigel Tao uploaded patch set #2 to this change.

View Change

compress/zlib: tighten header CINFO check

RFC 1950 section 2.2 "Data format" says "CINFO (Compression info)... For
CM = 8... Values of CINFO above 7 are not allowed".

Change-Id: Ibbc1213125c7dc045f09901ee7746660e90b5fcd
---
M src/compress/zlib/reader.go
M src/compress/zlib/reader_test.go
2 files changed, 25 insertions(+), 3 deletions(-)

To view, visit change 395734. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ibbc1213125c7dc045f09901ee7746660e90b5fcd
Gerrit-Change-Number: 395734
Gerrit-PatchSet: 2
Gerrit-Owner: Nigel Tao <nige...@golang.org>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Joseph Tsai <joe...@digital-static.net>
Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
Gerrit-Attention: Joseph Tsai <joe...@digital-static.net>
Gerrit-Attention: Nigel Tao <nige...@golang.org>
Gerrit-MessageType: newpatchset

Nigel Tao (Gerrit)

unread,
Mar 29, 2022, 10:16:18 PM3/29/22
to goph...@pubsubhelper.golang.org, Gopher Robot, Matthew Dempsky, Joseph Tsai, golang-co...@googlegroups.com

Attention is currently required from: Joseph Tsai.

Patch set 2:Trust +1

View Change

1 comment:

  • File src/compress/zlib/reader.go:

    • nit: keep the CM==zlibDeflate check first? […]

      Done

To view, visit change 395734. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ibbc1213125c7dc045f09901ee7746660e90b5fcd
Gerrit-Change-Number: 395734
Gerrit-PatchSet: 2
Gerrit-Owner: Nigel Tao <nige...@golang.org>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Joseph Tsai <joe...@digital-static.net>
Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
Gerrit-Reviewer: Nigel Tao <nige...@golang.org>
Gerrit-Attention: Joseph Tsai <joe...@digital-static.net>
Gerrit-Comment-Date: Wed, 30 Mar 2022 02:16:11 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Matthew Dempsky <mdem...@google.com>
Gerrit-MessageType: comment

Nigel Tao (Gerrit)

unread,
Mar 29, 2022, 10:16:24 PM3/29/22
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Gopher Robot, Matthew Dempsky, Joseph Tsai, golang-co...@googlegroups.com

Nigel Tao submitted this change.

View Change



1 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:

```
The name of the file: src/compress/zlib/reader.go
Insertions: 1, Deletions: 1.

@@ -146,7 +146,7 @@

return z.err
}
h := uint(z.scratch[0])<<8 | uint(z.scratch[1])
-	if (z.scratch[0]>>4 > zlibMaxWindow) || (z.scratch[0]&0x0f != zlibDeflate) || (h%31 != 0) {
+ if (z.scratch[0]&0x0f != zlibDeflate) || (z.scratch[0]>>4 > zlibMaxWindow) || (h%31 != 0) {

z.err = ErrHeader
return z.err
}
```

Approvals: Matthew Dempsky: Looks good to me, approved Nigel Tao: Trusted
compress/zlib: tighten header CINFO check

RFC 1950 section 2.2 "Data format" says "CINFO (Compression info)... For
CM = 8... Values of CINFO above 7 are not allowed".

Change-Id: Ibbc1213125c7dc045f09901ee7746660e90b5fcd
Reviewed-on: https://go-review.googlesource.com/c/go/+/395734
Reviewed-by: Matthew Dempsky <mdem...@google.com>
Trust: Nigel Tao <nige...@golang.org>

---
M src/compress/zlib/reader.go
M src/compress/zlib/reader_test.go
2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/src/compress/zlib/reader.go b/src/compress/zlib/reader.go
index a195b38..343a18b 100644

--- a/src/compress/zlib/reader.go
+++ b/src/compress/zlib/reader.go
@@ -32,7 +32,10 @@
"io"
)

-const zlibDeflate = 8
+const (
+ zlibDeflate = 8
+ zlibMaxWindow = 7
+)

var (
// ErrChecksum is returned when reading ZLIB data that has an invalid checksum.
@@ -143,7 +146,7 @@
return z.err
}
h := uint(z.scratch[0])<<8 | uint(z.scratch[1])
- if (z.scratch[0]&0x0f != zlibDeflate) || (h%31 != 0) {
+	if (z.scratch[0]&0x0f != zlibDeflate) || (z.scratch[0]>>4 > zlibMaxWindow) || (h%31 != 0) {

z.err = ErrHeader
return z.err
}
diff --git a/src/compress/zlib/reader_test.go b/src/compress/zlib/reader_test.go
index 70e33ba..20cec69 100644
--- a/src/compress/zlib/reader_test.go
+++ b/src/compress/zlib/reader_test.go
@@ -65,7 +65,14 @@
nil,
},
{
- "bad header",
+ "bad header (CINFO)",
+ "",
+ []byte{0x88, 0x98, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01},
+ nil,
+ ErrHeader,
+ },
+ {
+ "bad header (FCHECK)",
"",
[]byte{0x78, 0x9f, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01},
nil,

To view, visit change 395734. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ibbc1213125c7dc045f09901ee7746660e90b5fcd
Gerrit-Change-Number: 395734
Gerrit-PatchSet: 3
Gerrit-Owner: Nigel Tao <nige...@golang.org>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Joseph Tsai <joe...@digital-static.net>
Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
Gerrit-Reviewer: Nigel Tao <nige...@golang.org>
Gerrit-MessageType: merged
Reply all
Reply to author
Forward
0 new messages