Skip to content

Commit 176900a

Browse files
dsnetandybons
authored andcommitted
[release-branch.go1.10] archive/zip: fix handling of Info-ZIP Unix extended timestamps
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 <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-on: https://go-review.googlesource.com/102782 Run-TryBot: Andrew Bonventre <[email protected]> Reviewed-by: Joe Tsai <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent e1c0834 commit 176900a

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

src/archive/zip/reader.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ parseExtras:
366366
epoch := time.Date(1601, time.January, 1, 0, 0, 0, 0, time.UTC)
367367
modified = time.Unix(epoch.Unix()+secs, nsecs)
368368
}
369-
case unixExtraID:
369+
case unixExtraID, infoZipUnixExtraID:
370370
if len(fieldBuf) < 8 {
371371
continue parseExtras
372372
}
@@ -379,12 +379,6 @@ parseExtras:
379379
}
380380
ts := int64(fieldBuf.uint32()) // ModTime since Unix epoch
381381
modified = time.Unix(ts, 0)
382-
case infoZipUnixExtraID:
383-
if len(fieldBuf) < 4 {
384-
continue parseExtras
385-
}
386-
ts := int64(fieldBuf.uint32()) // ModTime since Unix epoch
387-
modified = time.Unix(ts, 0)
388382
}
389383
}
390384

src/archive/zip/reader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ var tests = []ZipTest{
414414
Name: "test.txt",
415415
Content: []byte{},
416416
Size: 1<<32 - 1,
417-
Modified: time.Date(2017, 10, 31, 21, 17, 27, 0, timeZone(-7*time.Hour)),
417+
Modified: time.Date(2017, 10, 31, 21, 11, 57, 0, timeZone(-7*time.Hour)),
418418
Mode: 0644,
419419
},
420420
},

0 commit comments

Comments
 (0)