From 338ade095a389dc15a98d34746fa8c2077b1cd9c Mon Sep 17 00:00:00 2001 From: Leif <33893697+lnatpunblhna@users.noreply.github.com> Date: Fri, 26 Jan 2024 16:07:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E4=B8=AD=E5=87=BA=E7=8E=B0=E9=9D=9EUTF-8=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E5=AF=BC=E8=87=B4=E6=97=A5=E5=BF=97=E9=94=99?= =?UTF-8?q?=E8=AF=AF=20(#3715)=20(#3716)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/container.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/app/service/container.go b/backend/app/service/container.go index e77e1930d..fbff77f21 100644 --- a/backend/app/service/container.go +++ b/backend/app/service/container.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "github.com/pkg/errors" "io" "os" "os/exec" @@ -15,6 +16,7 @@ import ( "sync" "syscall" "time" + "unicode/utf8" "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/buserr" @@ -637,6 +639,9 @@ func (u *ContainerService) ContainerLogs(wsConn *websocket.Conn, containerType, cmd := exec.Command("bash", "-c", command) if !follow { stdout, _ := cmd.CombinedOutput() + if !utf8.Valid(stdout) { + return errors.New("invalid utf8") + } if err := wsConn.WriteMessage(websocket.TextMessage, stdout); err != nil { global.LOG.Errorf("send message with log to ws failed, err: %v", err) } @@ -678,6 +683,10 @@ func (u *ContainerService) ContainerLogs(wsConn *websocket.Conn, containerType, global.LOG.Errorf("read bytes from log failed, err: %v", err) continue } + // check if the bytes is valid utf8 + if !utf8.Valid(buffer[:n]) { + continue + } if err = wsConn.WriteMessage(websocket.TextMessage, buffer[:n]); err != nil { global.LOG.Errorf("send message with log to ws failed, err: %v", err) return err