From 3d941cd2d0897d204a2f36fe70eb6011892461d9 Mon Sep 17 00:00:00 2001 From: lvxiangcong Date: Mon, 17 Feb 2025 10:19:48 +0800 Subject: [PATCH] backport-fix-cve-2022-34038 --- pkg/ioutil/pagewriter.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/ioutil/pagewriter.go b/pkg/ioutil/pagewriter.go index cf9a8dc..10d921d 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,17 @@ 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 { + Assert(pageBytes > 0, "pageBytes %d is an invalid value, it must be greater than 0", pageBytes) return &PageWriter{ w: w, pageOffset: pageOffset, -- 2.46.0