Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/google/go-containerregistry v0.20.7
github.com/gorilla/websocket v1.5.3
github.com/itchyny/json2yaml v0.1.4
github.com/kernel/hypeman-go v0.17.0
github.com/kernel/hypeman-go v0.18.0
github.com/knadh/koanf/parsers/yaml v1.1.0
github.com/knadh/koanf/providers/env v1.1.0
github.com/knadh/koanf/providers/file v1.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 h1:8Tjv8EJ+pM1xP8mK6egEbD1OgnV
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2/go.mod h1:pkJQ2tZHJ0aFOVEEot6oZmaVEZcRme73eIFmhiVuRWs=
github.com/itchyny/json2yaml v0.1.4 h1:/pErVOXGG5iTyXHi/QKR4y3uzhLjGTEmmJIy97YT+k8=
github.com/itchyny/json2yaml v0.1.4/go.mod h1:6iudhBZdarpjLFRNj+clWLAkGft+9uCcjAZYXUH9eGI=
github.com/kernel/hypeman-go v0.17.0 h1:OaGS0pFUwXYaFtlXaIQleokgNM7Z+KO0mGhL953yiMQ=
github.com/kernel/hypeman-go v0.17.0/go.mod h1:guRrhyP9QW/ebUS1UcZ0uZLLJeGAAhDNzSi68U4M9hI=
github.com/kernel/hypeman-go v0.18.0 h1:lznsO93fxpBfOLzr0mdMEMM0SsJHbeQhZ1Z7uyxLmOI=
github.com/kernel/hypeman-go v0.18.0/go.mod h1:guRrhyP9QW/ebUS1UcZ0uZLLJeGAAhDNzSi68U4M9hI=
github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
github.com/knadh/koanf/maps v0.1.2 h1:RBfmAW5CnZT+PJ1CVc1QSJKf4Xu9kxfQgYVQSu8hpbo=
Expand Down
14 changes: 12 additions & 2 deletions pkg/cmd/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ var standbyCmd = cli.Command{
Name: "compression-enabled",
Usage: "Enable memory compression for this standby operation",
},
&cli.StringFlag{
Name: "compression-delay",
Usage: `Delay before standby snapshot compression begins (e.g., "30s", "5m")`,
},
&cli.StringFlag{
Name: "compression-algorithm",
Usage: `Compression algorithm: "zstd" or "lz4"`,
Expand Down Expand Up @@ -153,7 +157,12 @@ func handleStandby(ctx context.Context, cmd *cli.Command) error {
}

params := hypeman.InstanceStandbyParams{}
if cmd.IsSet("compression-enabled") || cmd.IsSet("compression-algorithm") || cmd.IsSet("compression-level") {
if cmd.IsSet("compression-enabled") || cmd.IsSet("compression-delay") || cmd.IsSet("compression-algorithm") || cmd.IsSet("compression-level") {
request := hypeman.StandbyInstanceRequestParam{}
if delay := cmd.String("compression-delay"); delay != "" {
request.CompressionDelay = hypeman.Opt(delay)
}

compression := shared.SnapshotCompressionConfigParam{
Enabled: cmd.Bool("compression-enabled"),
}
Expand All @@ -170,7 +179,8 @@ func handleStandby(ctx context.Context, cmd *cli.Command) error {
}
compression.Algorithm = parsedAlgorithm
}
params.Compression = compression
request.Compression = compression
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing nested guard sends unintended compression config

Medium Severity

In lifecycle.go, the SnapshotCompressionConfigParam is unconditionally built inside the outer if block. When a user passes only --compression-delay, the compression config is still created with Enabled: true (via the fallback on line 170), even though the user never requested compression. In contrast, run.go correctly uses a nested if to guard the compression config creation, only building it when snapshot-compression-enabled, snapshot-compression-algorithm, or snapshot-compression-level is set. The lifecycle.go code is missing this same nested guard, causing unintended side effects.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 08a550e. Configure here.

params.StandbyInstanceRequest = request
}

fmt.Fprintf(os.Stderr, "Putting %s into standby...\n", args[0])
Expand Down
43 changes: 26 additions & 17 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ Examples:
Name: "snapshot-compression-enabled",
Usage: "Enable snapshot memory compression for this instance policy",
},
&cli.StringFlag{
Name: "snapshot-compression-delay",
Usage: `Delay before standby snapshot compression begins (e.g., "30s", "5m")`,
},
&cli.StringFlag{
Name: "snapshot-compression-algorithm",
Usage: `Snapshot compression algorithm: "zstd" or "lz4"`,
Expand Down Expand Up @@ -347,26 +351,31 @@ func handleRun(ctx context.Context, cmd *cli.Command) error {
}

// Snapshot policy compression
if cmd.IsSet("snapshot-compression-enabled") || cmd.IsSet("snapshot-compression-algorithm") || cmd.IsSet("snapshot-compression-level") {
compression := shared.SnapshotCompressionConfigParam{
Enabled: cmd.Bool("snapshot-compression-enabled"),
}
if !cmd.IsSet("snapshot-compression-enabled") {
compression.Enabled = true
if cmd.IsSet("snapshot-compression-enabled") || cmd.IsSet("snapshot-compression-delay") || cmd.IsSet("snapshot-compression-algorithm") || cmd.IsSet("snapshot-compression-level") {
policy := hypeman.SnapshotPolicyParam{}
if delay := cmd.String("snapshot-compression-delay"); delay != "" {
policy.StandbyCompressionDelay = hypeman.Opt(delay)
}
if cmd.IsSet("snapshot-compression-level") {
compression.Level = hypeman.Opt(int64(cmd.Int("snapshot-compression-level")))
}
if algorithm := cmd.String("snapshot-compression-algorithm"); algorithm != "" {
parsedAlgorithm, err := parseSnapshotCompressionAlgorithm(algorithm)
if err != nil {
return fmt.Errorf("invalid snapshot compression algorithm: %w", err)
if cmd.IsSet("snapshot-compression-enabled") || cmd.IsSet("snapshot-compression-algorithm") || cmd.IsSet("snapshot-compression-level") {
compression := shared.SnapshotCompressionConfigParam{
Enabled: cmd.Bool("snapshot-compression-enabled"),
}
compression.Algorithm = parsedAlgorithm
}
params.SnapshotPolicy = hypeman.SnapshotPolicyParam{
Compression: compression,
if !cmd.IsSet("snapshot-compression-enabled") {
compression.Enabled = true
}
if cmd.IsSet("snapshot-compression-level") {
compression.Level = hypeman.Opt(int64(cmd.Int("snapshot-compression-level")))
}
if algorithm := cmd.String("snapshot-compression-algorithm"); algorithm != "" {
parsedAlgorithm, err := parseSnapshotCompressionAlgorithm(algorithm)
if err != nil {
return fmt.Errorf("invalid snapshot compression algorithm: %w", err)
}
compression.Algorithm = parsedAlgorithm
}
policy.Compression = compression
}
params.SnapshotPolicy = policy
}

// Volume mounts
Expand Down
Loading