Conversation
| activeDeadlineSeconds := int64(m.config.JobTimeoutMinutes * 60) | ||
|
|
||
| // backoffLimit from config. | ||
| backoffLimit := int32(m.config.MaxRetries) |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
Generally, to fix this kind of issue you either (a) parse directly into the final integer type with an appropriate bit size, or (b) ensure that any narrowing conversion is preceded by an explicit upper/lower bound check that clamps or rejects out‑of‑range values. Here we can’t change the overall configuration loading semantics much, but we can safely bound MaxRetries at the point where it is converted to int32 for Kubernetes’ backoffLimit.
The best minimal fix is in internal/controller/image_job_manager.go inside buildJobObject. Instead of directly doing backoffLimit := int32(m.config.MaxRetries), we should sanitize m.config.MaxRetries into a local int32 with a small, reasonable upper bound. For example, treat any non‑positive value as “unset” and fall back to a default (e.g., 3), and cap excessively large values at a defined maximum (e.g., 10 or some other small constant) before converting. This avoids overflow, preserves existing behavior for normal values, and does not require changing config parsing or struct types.
Concretely:
- In
buildJobObject, replace the single linebackoffLimit := int32(m.config.MaxRetries)with a small block:- Read
m.config.MaxRetriesinto a localretriesvariable. - If
retries <= 0, set it to a default (e.g., 1 or 3). - If
retries > someMax, clamp it tosomeMax. - Then convert to
int32.
- Read
- No new imports are needed; we only use basic integer comparison and literals.
- All other logic (timeouts, TTL, env vars) remains unchanged.
This guarantees that the int32 cast is safe regardless of the architecture or environment variable value and keeps behavior for normal, in‑range values effectively the same (other than defining sane bounds when misconfigured).
| @@ -318,8 +318,16 @@ | ||
| // Compute activeDeadlineSeconds from config. | ||
| activeDeadlineSeconds := int64(m.config.JobTimeoutMinutes * 60) | ||
|
|
||
| // backoffLimit from config. | ||
| backoffLimit := int32(m.config.MaxRetries) | ||
| // backoffLimit from config. Clamp to a safe, reasonable range before converting to int32. | ||
| retries := m.config.MaxRetries | ||
| if retries <= 0 { | ||
| // Use a small, sane default if unset or negative. | ||
| retries = 1 | ||
| } else if retries > 10 { | ||
| // Prevent overflow and unreasonable retry counts. | ||
| retries = 10 | ||
| } | ||
| backoffLimit := int32(retries) | ||
|
|
||
| ttl := int32(ttlSecondsAfterFinished) | ||
|
|
[Title]
📚 Description of Changes
Provide an overview of your changes and why they’re needed. Link to any related issues (e.g., "Fixes #123"). If your PR fixes a bug, resolves a feature request, or updates documentation, please explain how.
What Changed:
(Describe the modifications, additions, or removals.)
Why This Change:
(Explain the problem this PR addresses or the improvement it provides.)
Affected Components:
(Which component does this change affect? - put x for all components)
Compose
K8s
Other (please specify)
❓ Motivation and Context
Why is this change required? What problem does it solve?
Context:
(Provide background information or link to related discussions/issues.)
Relevant Tasks/Issues:
(e.g., Fixes: #GitHub Issue)
🔍 Types of Changes
Indicate which type of changes your code introduces (check all that apply):
🔬 QA / Verification Steps
Describe the steps a reviewer should take to verify your changes:
make testto verify all tests pass.")make create-kind && make deploy.")✅ Global Checklist
Please check all boxes that apply:
Summary by Gitar
ImageAnalysisResultCRD for storing dive analysis metrics, layer breakdown, and workload referencesThis will update automatically on new commits.