]> Cypherpunks repositories - gostls13.git/commitdiff
Check gzip strings for NUL elements, since they are NUL-terminated
authorNigel Tao <nigeltao@golang.org>
Sat, 30 Jan 2010 01:21:51 +0000 (12:21 +1100)
committerNigel Tao <nigeltao@golang.org>
Sat, 30 Jan 2010 01:21:51 +0000 (12:21 +1100)
on the wire.

R=rsc
CC=golang-dev
https://golang.org/cl/194146

src/pkg/compress/gzip/gunzip.go
src/pkg/compress/gzip/gzip.go

index 6a1b9fac37629ef6b24541a4ba256f30bc6c0237..ea1d2103440bbef479b26e627e4b58c6e72f5d87 100644 (file)
@@ -104,7 +104,7 @@ func (z *Inflater) readString() (string, os.Error) {
                        return "", err
                }
                if z.buf[i] == 0 {
-                       // GZIP (RFC 1952) specifies that strings are null-terminated ISO 8859-1 (Latin-1).
+                       // GZIP (RFC 1952) specifies that strings are NUL-terminated ISO 8859-1 (Latin-1).
                        // TODO(nigeltao): Convert from ISO 8859-1 (Latin-1) to UTF-8.
                        return string(z.buf[0:i]), nil
                }
index c17e6e7e0ee7fd5bda2e007e1545233386ee2037..7ce0e8cd2f30f5064927ccebb97cbf1c08e610a9 100644 (file)
@@ -85,11 +85,11 @@ func (z *Deflater) writeBytes(b []byte) os.Error {
 
 // writeString writes a string (in ISO 8859-1 (Latin-1) format) to z.w.
 func (z *Deflater) writeString(s string) os.Error {
-       // GZIP (RFC 1952) specifies that strings are null-terminated ISO 8859-1 (Latin-1).
+       // GZIP (RFC 1952) specifies that strings are NUL-terminated ISO 8859-1 (Latin-1).
        // TODO(nigeltao): Convert from UTF-8 to ISO 8859-1 (Latin-1).
        for _, v := range s {
-               if v > 0x7f {
-                       return os.NewError("gzip.Write: Comment/Name character code was outside the 0x00-0x7f range")
+               if v == 0 || v > 0x7f {
+                       return os.NewError("gzip.Write: non-ASCII header string")
                }
        }
        _, err := io.WriteString(z.w, s)