Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zip: update CreateHeaderRaw to handle zip64 fields. #266

Merged
merged 1 commit into from Jun 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions zip/writer.go
Expand Up @@ -218,7 +218,7 @@ func (w *Writer) Close() error {
// allowed. To create a directory instead of a file, add a trailing
// slash to the name.
// The file's contents must be written to the io.Writer before the next
// call to Create, CreateHeader, or Close.
// call to Create, CreateHeader, CreateHeaderRaw, or Close.
func (w *Writer) Create(name string) (io.Writer, error) {
header := &FileHeader{
Name: name,
Expand Down Expand Up @@ -403,8 +403,10 @@ func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) {
// The file's contents must be written to the io.Writer before the next
// call to Create, Copy, CreateHeader, CreateHeaderRaw or Close.
//
// Using this requires knowledge of populating the FileHeader correctly.
// Generally using the Copy() function is recommended.
// Using this requires knowledge of populating the FileHeader correctly (the
// UncompressedSize64 and CRC32 fields should be set and valid for the contents
// written). For copying from an existing zip file, the Copy() function is
// recommended.
func (w *Writer) CreateHeaderRaw(fh *FileHeader) (io.Writer, error) {
if w.last != nil && !w.last.Closed() {
if err := w.last.Close(); err != nil {
Expand Down Expand Up @@ -669,6 +671,15 @@ func (w *rawWriter) Close() error {
fh := w.FileHeader
fh.CompressedSize64 = uint64(w.rawCount.count)

if fh.isZip64() {
fh.CompressedSize = uint32max
fh.UncompressedSize = uint32max
fh.ReaderVersion = zipVersion45 // requires 4.5 - File uses ZIP64 format extensions
} else {
fh.CompressedSize = uint32(fh.CompressedSize64)
fh.UncompressedSize = uint32(fh.UncompressedSize64)
}

// Write data descriptor. This is more complicated than one would
// think, see e.g. comments in zipfile.c:putextended() and
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7073588.
Expand Down