From a14f9e1e6ce137aed9c87038177e502b25938ba5 Mon Sep 17 00:00:00 2001 From: Catherine Date: Fri, 3 Oct 2025 06:01:51 +0000 Subject: [PATCH] Use `int64`, not `uint32`, for sizes in the manifest. This change eliminates a number of rather sketchy casts. This conversion is a no-op for the wire format, explicitly per Protobuf documentation. --- src/extract.go | 6 +++--- src/fetch.go | 2 +- src/manifest.go | 8 ++++---- src/schema.pb.go | 12 ++++++------ src/schema.proto | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/extract.go b/src/extract.go index e22a604..6887fdb 100644 --- a/src/extract.go +++ b/src/extract.go @@ -58,12 +58,12 @@ func ExtractTar(reader io.Reader) (*Manifest, error) { } manifestEntry.Type = Type_InlineFile.Enum() - manifestEntry.Size = proto.Uint32(uint32(header.Size)) + manifestEntry.Size = proto.Int64(header.Size) manifestEntry.Data = fileData case tar.TypeSymlink: manifestEntry.Type = Type_Symlink.Enum() - manifestEntry.Size = proto.Uint32(uint32(header.Size)) + manifestEntry.Size = proto.Int64(header.Size) manifestEntry.Data = []byte(header.Linkname) case tar.TypeDir: @@ -145,7 +145,7 @@ func ExtractZip(reader io.Reader) (*Manifest, error) { } manifestEntry.Type = Type_InlineFile.Enum() - manifestEntry.Size = proto.Uint32(uint32(file.UncompressedSize64)) + manifestEntry.Size = proto.Int64(int64(file.UncompressedSize64)) manifestEntry.Data = fileData } else { manifestEntry.Type = Type_Directory.Enum() diff --git a/src/fetch.go b/src/fetch.go index dcb66bc..50ca85d 100644 --- a/src/fetch.go +++ b/src/fetch.go @@ -101,7 +101,7 @@ func FetchRepository(ctx context.Context, repoURL string, branch string) (*Manif } else { manifestEntry.Type = Type_InlineFile.Enum() } - manifestEntry.Size = proto.Uint32(uint32(blob.Size)) + manifestEntry.Size = proto.Int64(blob.Size) manifestEntry.Data = data } else if entry.Mode == filemode.Dir { manifestEntry.Type = Type_Directory.Enum() diff --git a/src/manifest.go b/src/manifest.go index 5cdea3d..c387b1c 100644 --- a/src/manifest.go +++ b/src/manifest.go @@ -131,14 +131,14 @@ func CompressFiles(ctx context.Context, manifest *Manifest) { span, _ := ObserveFunction(ctx, "CompressFiles") defer span.Finish() - var originalSize, transformedSize uint32 + var originalSize, transformedSize int64 for _, entry := range manifest.Contents { if entry.GetType() == Type_InlineFile && entry.GetXfrm() == Transform_None { originalSize += entry.GetSize() compressedData := zstdEncoder.EncodeAll(entry.GetData(), make([]byte, 0, entry.GetSize())) if len(compressedData) < int(*entry.Size) { entry.Data = compressedData - entry.Size = proto.Uint32(uint32(len(entry.Data))) + entry.Size = proto.Int64(int64(len(entry.Data))) entry.Xfrm = Transform_Zstandard.Enum() } transformedSize += entry.GetSize() @@ -186,11 +186,11 @@ func StoreManifest(ctx context.Context, name string, manifest *Manifest) (*Manif Contents: make(map[string]*Entry), Redirects: manifest.Redirects, Problems: manifest.Problems, - TotalSize: proto.Uint32(0), + TotalSize: proto.Int64(0), } for name, entry := range manifest.Contents { cannotBeInlined := entry.GetType() == Type_InlineFile && - entry.GetSize() > uint32(config.Limits.MaxInlineFileSize.Bytes()) + entry.GetSize() > int64(config.Limits.MaxInlineFileSize.Bytes()) if cannotBeInlined { extManifest.Contents[name] = &Entry{ Type: Type_ExternalFile.Enum(), diff --git a/src/schema.pb.go b/src/schema.pb.go index a90d456..b040af6 100644 --- a/src/schema.pb.go +++ b/src/schema.pb.go @@ -134,7 +134,7 @@ type Entry struct { Type *Type `protobuf:"varint,1,opt,name=type,enum=Type" json:"type,omitempty"` // Only present for `type == InlineFile` and `type == ExternalFile`. // For transformed entries, refers to the post-transformation (compressed) size. - Size *uint32 `protobuf:"varint,2,opt,name=size" json:"size,omitempty"` + Size *int64 `protobuf:"varint,2,opt,name=size" json:"size,omitempty"` // Meaning depends on `type`: // - If `type == InlineFile`, contains file data. // - If `type == ExternalFile`, contains blob name (an otherwise unspecified @@ -186,7 +186,7 @@ func (x *Entry) GetType() Type { return Type_Invalid } -func (x *Entry) GetSize() uint32 { +func (x *Entry) GetSize() int64 { if x != nil && x.Size != nil { return *x.Size } @@ -337,7 +337,7 @@ type Manifest struct { Commit *string `protobuf:"bytes,3,opt,name=commit" json:"commit,omitempty"` // Contents Contents map[string]*Entry `protobuf:"bytes,4,rep,name=contents" json:"contents,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` - TotalSize *uint32 `protobuf:"varint,5,opt,name=total_size,json=totalSize" json:"total_size,omitempty"` + TotalSize *int64 `protobuf:"varint,5,opt,name=total_size,json=totalSize" json:"total_size,omitempty"` // Netlify-style `_redirects` Redirects []*Redirect `protobuf:"bytes,6,rep,name=redirects" json:"redirects,omitempty"` // Diagnostics for non-fatal errors @@ -404,7 +404,7 @@ func (x *Manifest) GetContents() map[string]*Entry { return nil } -func (x *Manifest) GetTotalSize() uint32 { +func (x *Manifest) GetTotalSize() int64 { if x != nil && x.TotalSize != nil { return *x.TotalSize } @@ -432,7 +432,7 @@ const file_schema_proto_rawDesc = "" + "\fschema.proto\"j\n" + "\x05Entry\x12\x19\n" + "\x04type\x18\x01 \x01(\x0e2\x05.TypeR\x04type\x12\x12\n" + - "\x04size\x18\x02 \x01(\rR\x04size\x12\x12\n" + + "\x04size\x18\x02 \x01(\x03R\x04size\x12\x12\n" + "\x04data\x18\x03 \x01(\fR\x04data\x12\x1e\n" + "\x04xfrm\x18\x04 \x01(\x0e2\n" + ".TransformR\x04xfrm\"\\\n" + @@ -450,7 +450,7 @@ const file_schema_proto_rawDesc = "" + "\x06commit\x18\x03 \x01(\tR\x06commit\x123\n" + "\bcontents\x18\x04 \x03(\v2\x17.Manifest.ContentsEntryR\bcontents\x12\x1d\n" + "\n" + - "total_size\x18\x05 \x01(\rR\ttotalSize\x12'\n" + + "total_size\x18\x05 \x01(\x03R\ttotalSize\x12'\n" + "\tredirects\x18\x06 \x03(\v2\t.RedirectR\tredirects\x12$\n" + "\bproblems\x18\a \x03(\v2\b.ProblemR\bproblems\x1aC\n" + "\rContentsEntry\x12\x10\n" + diff --git a/src/schema.proto b/src/schema.proto index f8ff0d7..b97ca95 100644 --- a/src/schema.proto +++ b/src/schema.proto @@ -26,7 +26,7 @@ message Entry { Type type = 1; // Only present for `type == InlineFile` and `type == ExternalFile`. // For transformed entries, refers to the post-transformation (compressed) size. - uint32 size = 2; + int64 size = 2; // Meaning depends on `type`: // * If `type == InlineFile`, contains file data. // * If `type == ExternalFile`, contains blob name (an otherwise unspecified @@ -61,7 +61,7 @@ message Manifest { // Contents map contents = 4; - uint32 total_size = 5; + int64 total_size = 5; // Netlify-style `_redirects` repeated Redirect redirects = 6;