Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import (
"fmt"
"io"
"strconv"
"time"
)

var (
ErrWriteTooLong = errors.New("ar: write too long")

// Epoch is the Unix epoch, 00:00:00 UTC on 1970-01-01.
Epoch = time.Unix(0, 0)
)

// Writer provides sequential writing of an ar archive.
Expand Down Expand Up @@ -228,6 +232,11 @@ func (aw *Writer) WriteHeader(hdr *Header) error {
// This should be unreachable.
return errors.New("ar: unsupported variant")
}
// Modification times before the Unix epoch cannot meaningfully be represented in ar headers, which
// store times as stringified Unix times - ensure the modification time is at least the epoch.
if hdr.ModTime.Before(Epoch) {
hdr.ModTime = Epoch
}
aw.numeric(s.next(12), hdr.ModTime.Unix())
aw.numeric(s.next(6), int64(hdr.Uid))
aw.numeric(s.next(6), int64(hdr.Gid))
Expand Down