Skip to content

Commit 11aef92

Browse files
authored
pkg/settings/cresettings: fix WASMBinarySizeLimit (#1634)
1 parent e0b8677 commit 11aef92

5 files changed

Lines changed: 19 additions & 11 deletions

File tree

pkg/settings/cresettings/defaults.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"ExecutionResponseLimit": "100kb",
3131
"WASMExecutionTimeout": "1m0s",
3232
"WASMMemoryLimit": "100mb",
33-
"WASMBinarySizeLimit": "30mb",
33+
"WASMBinarySizeLimit": "100mb",
3434
"WASMCompressedBinarySizeLimit": "20mb",
3535
"WASMConfigSizeLimit": "30mb",
3636
"WASMSecretsSizeLimit": "30mb",

pkg/settings/cresettings/defaults.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ExecutionTimeout = '10m0s'
3030
ExecutionResponseLimit = '100kb'
3131
WASMExecutionTimeout = '1m0s'
3232
WASMMemoryLimit = '100mb'
33-
WASMBinarySizeLimit = '30mb'
33+
WASMBinarySizeLimit = '100mb'
3434
WASMCompressedBinarySizeLimit = '20mb'
3535
WASMConfigSizeLimit = '30mb'
3636
WASMSecretsSizeLimit = '30mb'

pkg/settings/cresettings/settings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ var Default = Schema{
7676
ExecutionResponseLimit: Size(100 * config.KByte),
7777
WASMExecutionTimeout: Duration(60 * time.Second),
7878
WASMMemoryLimit: Size(100 * config.MByte),
79-
WASMBinarySizeLimit: Size(30 * config.MByte),
79+
WASMBinarySizeLimit: Size(100 * config.MByte),
8080
WASMCompressedBinarySizeLimit: Size(20 * config.MByte),
8181
WASMConfigSizeLimit: Size(30 * config.MByte),
8282
WASMSecretsSizeLimit: Size(30 * config.MByte),

pkg/workflows/wasm/host/module.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func NewModule(ctx context.Context, modCfg *ModuleConfig, binary []byte, opts ..
251251
// this is to prevent decompression bombs
252252
if err := modCfg.MaxCompressedBinaryLimiter.Check(ctx, config.SizeOf(binary)); err != nil {
253253
if errors.Is(err, limits.ErrorBoundLimited[config.Size]{}) {
254-
return nil, fmt.Errorf("compressed binary size exceeds the maximum allowed size of %d bytes: %w", modCfg.MaxCompressedBinarySize, err)
254+
return nil, fmt.Errorf("compressed binary size exceeds the maximum allowed size: %w", err)
255255
}
256256
return nil, fmt.Errorf("failed to check compressed binary size limit: %w", err)
257257
}
@@ -273,7 +273,7 @@ func NewModule(ctx context.Context, modCfg *ModuleConfig, binary []byte, opts ..
273273
// The Read() method will return io.EOF, and ReadAll will gracefully handle it and return nil.
274274
if err := modCfg.MaxDecompressedBinaryLimiter.Check(ctx, config.SizeOf(binary)); err != nil {
275275
if errors.Is(err, limits.ErrorBoundLimited[config.Size]{}) {
276-
return nil, fmt.Errorf("decompressed binary size reached the maximum allowed size of %d bytes: %w", modCfg.MaxDecompressedBinarySize, err)
276+
return nil, fmt.Errorf("decompressed binary size reached the maximum allowed size: %w", err)
277277
}
278278
return nil, fmt.Errorf("failed to check decompressed binary size limit: %w", err)
279279
}

pkg/workflows/wasm/host/wasm_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import (
2121

2222
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb"
2323
capabilitiespb "github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb"
24+
"github.com/smartcontractkit/chainlink-common/pkg/config"
2425
"github.com/smartcontractkit/chainlink-common/pkg/logger"
26+
"github.com/smartcontractkit/chainlink-common/pkg/settings/limits"
2527
wasmpb "github.com/smartcontractkit/chainlink-common/pkg/workflows/wasm/pb"
2628
valuespb "github.com/smartcontractkit/chainlink-protos/cre/go/values/pb"
2729
)
@@ -943,8 +945,10 @@ func TestModule_CompressedBinarySize(t *testing.T) {
943945
require.NoError(t, bwr.Close())
944946

945947
_, err = NewModule(t.Context(), &ModuleConfig{IsUncompressed: false, Logger: logger.Test(t)}, binary)
946-
default10mbLimit := fmt.Sprintf("binary size exceeds the maximum allowed size of %d bytes", defaultMaxCompressedBinarySize)
947-
require.ErrorContains(t, err, default10mbLimit)
948+
require.ErrorContains(t, err, "binary size exceeds the maximum allowed size")
949+
var limitErr limits.ErrorBoundLimited[config.Size]
950+
require.ErrorAs(t, err, &limitErr)
951+
assert.Equal(t, defaultMaxCompressedBinarySize, int(limitErr.Limit))
948952
})
949953

950954
t.Run("compressed binary size is bigger than the custom limit", func(t *testing.T) {
@@ -958,8 +962,10 @@ func TestModule_CompressedBinarySize(t *testing.T) {
958962
require.NoError(t, bwr.Close())
959963

960964
_, err = NewModule(t.Context(), &ModuleConfig{IsUncompressed: false, MaxCompressedBinarySize: customMaxCompressedBinarySize, Logger: logger.Test(t)}, binary)
961-
default10mbLimit := fmt.Sprintf("binary size exceeds the maximum allowed size of %d bytes", customMaxCompressedBinarySize)
962-
require.ErrorContains(t, err, default10mbLimit)
965+
require.ErrorContains(t, err, "binary size exceeds the maximum allowed size")
966+
var limitErr limits.ErrorBoundLimited[config.Size]
967+
require.ErrorAs(t, err, &limitErr)
968+
assert.Equal(t, customMaxCompressedBinarySize, uint64(limitErr.Limit))
963969
})
964970
}
965971

@@ -979,8 +985,10 @@ func TestModule_DecompressedBinarySize(t *testing.T) {
979985
t.Run("decompressed binary size is bigger than the limit", func(t *testing.T) {
980986
customDecompressedBinarySize := uint64(len(decompedBinary) - 1)
981987
_, err := NewModule(t.Context(), &ModuleConfig{IsUncompressed: false, MaxDecompressedBinarySize: customDecompressedBinarySize, Logger: logger.Test(t)}, binary)
982-
decompressedSizeExceeded := fmt.Sprintf("decompressed binary size reached the maximum allowed size of %d bytes", customDecompressedBinarySize)
983-
require.ErrorContains(t, err, decompressedSizeExceeded)
988+
require.ErrorContains(t, err, "decompressed binary size reached the maximum allowed size")
989+
var limitErr limits.ErrorBoundLimited[config.Size]
990+
require.ErrorAs(t, err, &limitErr)
991+
assert.Equal(t, customDecompressedBinarySize, uint64(limitErr.Limit))
984992
})
985993
}
986994

0 commit comments

Comments
 (0)