MCPcopy Create free account
hub / github.com/coder/coder / validateZipArchiveSize

Function validateZipArchiveSize

archive/archive.go:50–73  ·  view source on GitHub ↗

validateZipArchiveSize performs a metadata-based preflight size check before conversion. The actual tar output limit will still be enforced while streaming.

(zipReader *zip.Reader, maxSize int64)

Source from the content-addressed store, hash-verified

48// check before conversion. The actual tar output limit will still be
49// enforced while streaming.
50func validateZipArchiveSize(zipReader *zip.Reader, maxSize int64) error {
51 if maxSize < 0 {
52 return ErrArchiveTooLarge
53 }
54
55 maxBytes := uint64(maxSize)
56 totalBytes := uint64(tarEndBlockBytes)
57 if totalBytes > maxBytes {
58 return ErrArchiveTooLarge
59 }
60
61 for _, file := range zipReader.File {
62 entrySize, err := projectedTarEntrySize(file)
63 if err != nil {
64 return err
65 }
66 if entrySize > maxBytes-totalBytes {
67 return ErrArchiveTooLarge
68 }
69 totalBytes += entrySize
70 }
71
72 return nil
73}
74
75func projectedTarEntrySize(file *zip.File) (uint64, error) {
76 // Each tar entry contributes one header block plus its data

Callers 1

CreateTarFromZipFunction · 0.85

Calls 1

projectedTarEntrySizeFunction · 0.85

Tested by

no test coverage detected