Skip to content

Commit 10b60cd

Browse files
committed
Journal body memory limit should be greater than zero
1 parent 2e0ebf2 commit 10b60cd

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

core/util/memory_size.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ func (m *MemorySize) Set(value string) error {
3838
}
3939

4040
size, err := strconv.Atoi(value)
41-
if err != nil || size < 0 {
41+
42+
if err != nil {
4243
return fmt.Errorf("invalid memory size: %s", value)
4344
}
4445

46+
if size <= 0 {
47+
return fmt.Errorf("memory size must be greater than 0")
48+
}
49+
4550
*m = MemorySize(size * multiplier)
4651
return nil
4752
}

core/util/memory_size_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ func TestMemorySize_Set(t *testing.T) {
3535
var ms MemorySize
3636

3737
// Test inputs with invalid values
38-
Expect(ms.Set("10XYZ")).To(Not(BeNil())) // Unknown unit
39-
Expect(ms.Set("ABC")).To(Not(BeNil())) // Non-numeric input
40-
Expect(ms.Set("")).To(Not(BeNil())) // Empty input
41-
Expect(ms.Set("-5MB")).To(Not(BeNil())) // Negative value
38+
Expect(ms.Set("10XYZ")).To(MatchError("invalid memory size: 10XYZ"))
39+
Expect(ms.Set("ABC")).To(MatchError("invalid memory size: ABC"))
40+
Expect(ms.Set("")).To(MatchError("invalid memory size: "))
41+
Expect(ms.Set("-5MB")).To(MatchError("memory size must be greater than 0"))
42+
Expect(ms).To(Equal(MemorySize(0)))
4243
})
4344

4445
t.Run("boundary cases", func(t *testing.T) {

0 commit comments

Comments
 (0)