From 9fc6f39d714b20491ad0e54f70afe0e6066739be Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Fri, 4 Oct 2024 09:11:07 -0500 Subject: [PATCH] bake: raise maximum size limit and fix size check Similar to https://github.com/docker/buildx/pull/2716. Use the file size rather than the proto size, raise the allowed limit to the same value for consistency, and improve the error message to include the limit in human units. Signed-off-by: Jonathan A. Sternberg --- bake/remote.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bake/remote.go b/bake/remote.go index c176b413..9b7cd8c5 100644 --- a/bake/remote.go +++ b/bake/remote.go @@ -11,15 +11,17 @@ import ( controllerapi "github.com/docker/buildx/controller/pb" "github.com/docker/buildx/driver" "github.com/docker/buildx/util/progress" + "github.com/docker/go-units" "github.com/moby/buildkit/client" "github.com/moby/buildkit/client/llb" "github.com/moby/buildkit/frontend/dockerui" gwclient "github.com/moby/buildkit/frontend/gateway/client" "github.com/moby/buildkit/session" "github.com/pkg/errors" - "google.golang.org/protobuf/proto" ) +const maxBakeDefinitionSize = 2 * 1024 * 1024 // 2 MB + type Input struct { State *llb.State URL string @@ -178,9 +180,9 @@ func filesFromURLRef(ctx context.Context, c gwclient.Client, ref gwclient.Refere name := inp.URL inp.URL = "" - if len(dt) > proto.Size(stat) { - if proto.Size(stat) > 1024*512 { - return nil, errors.Errorf("non-archive definition URL bigger than maximum allowed size") + if int64(len(dt)) > stat.Size { + if stat.Size > maxBakeDefinitionSize { + return nil, errors.Errorf("non-archive definition URL bigger than maximum allowed size (%s)", units.HumanSize(maxBakeDefinitionSize)) } dt, err = ref.ReadFile(ctx, gwclient.ReadRequest{