Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: add bounds checks for remaining integer conversion alerts (#19418)

Danny Xu5fe285118c03
diff --git a/backend/plugin/parser/elasticsearch/parser.go b/backend/plugin/parser/elasticsearch/parser.go
index b5d83ed23c..d01d757eef 100644
--- a/backend/plugin/parser/elasticsearch/parser.go
+++ b/backend/plugin/parser/elasticsearch/parser.go
@@ -858,7 +858,7 @@ func (p *parser) array() ([]any, error) {
func (p *parser) string() (string, error) {
s := ""
- uffff := 0
+ var uffff int32
if p.ch == '"' {
if p.peek(0) == '"' && p.peek(1) == '"' {
// literal
@@ -899,7 +899,7 @@ func (p *parser) string() (string, error) {
if err != nil {
break
}
- uffff = (uffff << 4) + int(uint32(hex))
+ uffff = (uffff << 4) | int32(hex&0xF)
}
// Treat uffff as UTF-16 encoded rune.
s += string(rune(uffff))
diff --git a/backend/resources/postgres/postgres.go b/backend/resources/postgres/postgres.go
index f249aa9af3..d697211efd 100644
--- a/backend/resources/postgres/postgres.go
+++ b/backend/resources/postgres/postgres.go
@@ -4,6 +4,7 @@ package postgres
import (
"fmt"
"log/slog"
+ "math"
"os"
"os/exec"
"os/user"
@@ -113,6 +114,9 @@ func initDB(pgDataDir, pgUser string) error {
return err
}
if !sameUser {
+ if uid > math.MaxInt32 || gid > math.MaxInt32 {
+ return errors.Errorf("uid %d or gid %d exceeds maximum safe value", uid, gid)
+ }
slog.Info(fmt.Sprintf("Recursively change owner of data directory %q to bytebase...", pgDataDir))
for _, dir := range dirListToChown {
slog.Info(fmt.Sprintf("Change owner of %q to bytebase", dir))