]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.10] archive/zip: fix handling of Info-ZIP Unix extended timestamps
authorJoe Tsai <joetsai@digital-static.net>
Fri, 23 Feb 2018 23:08:11 +0000 (15:08 -0800)
committerAndrew Bonventre <andybons@golang.org>
Thu, 29 Mar 2018 06:07:32 +0000 (06:07 +0000)
The Info-ZIP Unix1 extra field is specified as such:
>>>
Value    Size   Description
-----    ----   -----------
0x5855   Short  tag for this extra block type ("UX")
TSize    Short  total data size for this block
AcTime   Long   time of last access (GMT/UTC)
ModTime  Long   time of last modification (GMT/UTC)
<<<

The previous handling was incorrect in that it read the AcTime field
instead of the ModTime field.

The test-osx.zip test unfortunately locked in the wrong behavior.
Manually parsing that ZIP file shows that the encoded MS-DOS
date and time are 0x4b5f and 0xa97d, which corresponds with a
date of 2017-10-31 21:11:58, which matches the correct mod time
(off by 1 second due to MS-DOS timestamp resolution).

Fixes #23901

Change-Id: I567824c66e8316b9acd103dbecde366874a4b7ef
Reviewed-on: https://go-review.googlesource.com/96895
Run-TryBot: Joe Tsai <joetsai@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-on: https://go-review.googlesource.com/102782
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/archive/zip/reader.go
src/archive/zip/reader_test.go

index 1563e74dfceda7d29f81ed8a367924c15a9115e3..2444106ba69e9e9b2fc194933b4d39b89ab311f2 100644 (file)
@@ -366,7 +366,7 @@ parseExtras:
                                epoch := time.Date(1601, time.January, 1, 0, 0, 0, 0, time.UTC)
                                modified = time.Unix(epoch.Unix()+secs, nsecs)
                        }
-               case unixExtraID:
+               case unixExtraID, infoZipUnixExtraID:
                        if len(fieldBuf) < 8 {
                                continue parseExtras
                        }
@@ -379,12 +379,6 @@ parseExtras:
                        }
                        ts := int64(fieldBuf.uint32()) // ModTime since Unix epoch
                        modified = time.Unix(ts, 0)
-               case infoZipUnixExtraID:
-                       if len(fieldBuf) < 4 {
-                               continue parseExtras
-                       }
-                       ts := int64(fieldBuf.uint32()) // ModTime since Unix epoch
-                       modified = time.Unix(ts, 0)
                }
        }
 
index 0d9040f76740c0e913117296ee0e19ffe6117c36..1e58b26b6e981cce0cf7578957050f30c914d2b9 100644 (file)
@@ -414,7 +414,7 @@ var tests = []ZipTest{
                                Name:     "test.txt",
                                Content:  []byte{},
                                Size:     1<<32 - 1,
-                               Modified: time.Date(2017, 10, 31, 21, 17, 27, 0, timeZone(-7*time.Hour)),
+                               Modified: time.Date(2017, 10, 31, 21, 11, 57, 0, timeZone(-7*time.Hour)),
                                Mode:     0644,
                        },
                },