Skip to content

archive/zip: Writer should only use extended timestamps for non-zero times #17403

Description

@dsnet

4c79ed5 caused a regression where a round-trip zip file does not preserve the same ModTime. The reason is because the logic for using extra timestamp is always applied in the Writer no matter what.

This is an issue for when the user doesn't set the ModifiedDate and ModifiedTime fields at all. Causing the Writer to convert a zero MS-DOS timestamp (gibberish) to a Unix timestamp (now gibberish) and back again. The fix is to only apply Extra timestamp only if the MS-DOS timestamp is non-zero.

See:

mt := uint32(h.FileHeader.ModTime().Unix())
var mbuf [9]byte // 2x uint16 + uint8 + uint32
eb := writeBuf(mbuf[:])
eb.uint16(exttsExtraId)
eb.uint16(5) // size = uint8 + uint32
eb.uint8(1) // flags = modtime
eb.uint32(mt) // ModTime
h.Extra = append(h.Extra, mbuf[:]...)

/cc @mattn

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions