44 lines
1.3 KiB
Diff
44 lines
1.3 KiB
Diff
From 10fdd367a2095806b025c1c54d30886369b3d586 Mon Sep 17 00:00:00 2001
|
|
From: bwzhang <zhangbowei@kylinos.cn>
|
|
Date: Fri, 19 Apr 2024 11:11:10 +0800
|
|
Subject: [PATCH] fix CVE-2022-34038
|
|
|
|
---
|
|
pkg/ioutil/pagewriter.go | 10 ++++++++++
|
|
1 file changed, 10 insertions(+)
|
|
|
|
diff --git a/pkg/ioutil/pagewriter.go b/pkg/ioutil/pagewriter.go
|
|
index cf9a8dc..4daaa9d 100644
|
|
--- a/pkg/ioutil/pagewriter.go
|
|
+++ b/pkg/ioutil/pagewriter.go
|
|
@@ -16,6 +16,7 @@ package ioutil
|
|
|
|
import (
|
|
"io"
|
|
+ "fmt"
|
|
)
|
|
|
|
var defaultBufferBytes = 128 * 1024
|
|
@@ -38,9 +39,18 @@ type PageWriter struct {
|
|
bufWatermarkBytes int
|
|
}
|
|
|
|
+// Assert will panic with a given formatted message if the given condition is false.
|
|
+func Assert(condition bool, msg string, v int) {
|
|
+ if !condition {
|
|
+ panic(fmt.Sprintf("assertion failed: "+msg, v))
|
|
+ }
|
|
+}
|
|
+
|
|
// NewPageWriter creates a new PageWriter. pageBytes is the number of bytes
|
|
// to write per page. pageOffset is the starting offset of io.Writer.
|
|
func NewPageWriter(w io.Writer, pageBytes, pageOffset int) *PageWriter {
|
|
+ // If pageBytes is 0 or less, it will trigger a panic directly
|
|
+ Assert(pageBytes > 0, "pageBytes %d is an invalid value, it must be greater than 0", pageBytes)
|
|
return &PageWriter{
|
|
w: w,
|
|
pageOffset: pageOffset,
|
|
--
|
|
2.20.1
|
|
|