]> Cypherpunks repositories - gostls13.git/commit
archive/zip: restrict UTF-8 detection for comment and name fields
authorJoe Tsai <joetsai@digital-static.net>
Mon, 23 Oct 2017 20:47:15 +0000 (13:47 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Wed, 25 Oct 2017 22:16:46 +0000 (22:16 +0000)
commit78805c07f4119ba0fc7bf2e462451d519f42f679
tree38daf0831eed23a5f4f59c3ba4df6b138b1ccd2f
parent4aa28896b7703dcb153f0effae4007dd098b6c06
archive/zip: restrict UTF-8 detection for comment and name fields

CL 39570 added support for automatically setting flag bit 11 to
indicate that the filename and comment fields are encoded in UTF-8,
which is (conventionally) the encoding using for most Go strings.

However, the detection added is too lose for two reasons:
* We need to ensure both fields are at least possibly UTF-8.
That is, if any field is definitely not UTF-8, then we can't set the bit.
* The utf8.ValidRune returns true for utf8.RuneError, which iterating
over a Go string automatically returns for invalid UTF-8.
Thus, we manually check for that value.

Updates #22367
Updates #10741

Change-Id: Ie8aae388432e546e44c6bebd06a00434373ca99e
Reviewed-on: https://go-review.googlesource.com/72791
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/archive/zip/writer.go
src/archive/zip/writer_test.go