Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions pkg/workflow/frontmatter_extraction_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package workflow

import (
"fmt"
"math"
"strings"
)

Expand Down Expand Up @@ -143,6 +144,22 @@ func (c *Compiler) extractSafetyPromptSetting(tools map[string]any) bool {
return true
}

// safeUintToInt safely converts uint to int, returning 0 if overflow would occur
func safeUintToInt(u uint) int {
if u > math.MaxInt {
return 0 // Return 0 (engine default) if value would overflow
}
return int(u)
}

// safeUint64ToInt safely converts uint64 to int, returning 0 if overflow would occur
func safeUint64ToInt(u uint64) int {
if u > math.MaxInt {
return 0 // Return 0 (engine default) if value would overflow
}
return int(u)
}

// extractToolsTimeout extracts the timeout setting from tools
// Returns 0 if not set (engines will use their own defaults)
func (c *Compiler) extractToolsTimeout(tools map[string]any) int {
Expand All @@ -152,16 +169,16 @@ func (c *Compiler) extractToolsTimeout(tools map[string]any) int {

// Check if timeout is explicitly set in tools
if timeoutValue, exists := tools["timeout"]; exists {
// Handle different numeric types
// Handle different numeric types with safe conversions to prevent overflow
switch v := timeoutValue.(type) {
case int:
return v
case int64:
return int(v)
case uint:
return int(v)
return safeUintToInt(v) // Safe conversion to prevent overflow (alert #418)
case uint64:
return int(v)
return safeUint64ToInt(v) // Safe conversion to prevent overflow (alert #416)
case float64:
return int(v)
}
Expand All @@ -180,16 +197,16 @@ func (c *Compiler) extractToolsStartupTimeout(tools map[string]any) int {

// Check if startup-timeout is explicitly set in tools
if timeoutValue, exists := tools["startup-timeout"]; exists {
// Handle different numeric types
// Handle different numeric types with safe conversions to prevent overflow
switch v := timeoutValue.(type) {
case int:
return v
case int64:
return int(v)
case uint:
return int(v)
return safeUintToInt(v) // Safe conversion to prevent overflow (alert #417)
case uint64:
return int(v)
return safeUint64ToInt(v) // Safe conversion to prevent overflow (alert #415)
case float64:
return int(v)
}
Expand Down
14 changes: 12 additions & 2 deletions pkg/workflow/safe_inputs_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ package workflow
import (
"encoding/json"
"fmt"
"math"
"strings"

"github.com/githubnext/gh-aw/pkg/logger"
)

var safeInputsLog = logger.New("workflow:safe_inputs")

// safeUint64ToIntForTimeout safely converts uint64 to int for timeout values
// Returns 0 (which signals to use engine defaults) if overflow would occur
func safeUint64ToIntForTimeout(u uint64) int {
if u > math.MaxInt {
return 0 // Return 0 (engine default) if value would overflow
}
return int(u)
}

// SafeInputsConfig holds the configuration for safe-inputs custom tools
type SafeInputsConfig struct {
Mode string // Transport mode: "http" (default) or "stdio"
Expand Down Expand Up @@ -211,7 +221,7 @@ func parseSafeInputsMap(safeInputsMap map[string]any) (*SafeInputsConfig, bool)
case int:
toolConfig.Timeout = t
case uint64:
toolConfig.Timeout = int(t)
toolConfig.Timeout = safeUint64ToIntForTimeout(t) // Safe conversion to prevent overflow (alert #414)
case float64:
toolConfig.Timeout = int(t)
case string:
Expand Down Expand Up @@ -395,7 +405,7 @@ func (c *Compiler) mergeSafeInputs(main *SafeInputsConfig, importedConfigs []str
case int:
toolConfig.Timeout = t
case uint64:
toolConfig.Timeout = int(t)
toolConfig.Timeout = safeUint64ToIntForTimeout(t) // Safe conversion to prevent overflow (alert #413)
case float64:
toolConfig.Timeout = int(t)
case string:
Expand Down