When fetchBytes is 0 (e.g., empty cached source content, or a zero-length upstream response that somehow passed validation), this causes a division by zero, producing +Inf or NaN which gets logged and could cause issues with metrics/monitoring systems.
Additionally, in processFromSourceOrFetch(), when source data is loaded from cache, fetchBytes is set to int64(len(sourceData)) which will be 0 for empty data, and this is passed to processAndStore().
Impact
Panics won't occur (Go float division by zero produces Inf), but:
Log output contains +Inf or NaN which breaks log parsing
Metrics systems may reject or mishandle these values
The underlying issue (empty source) should be caught earlier
Fix
Add a guard for fetchBytes == 0 before the division, and also validate that source data is non-empty before attempting to process it.
## Bug
In `internal/imgcache/service.go`, `processAndStore()` computes a size ratio:
```go
sizePercent := float64(outputSize) / float64(fetchBytes) * 100.0
```
When `fetchBytes` is 0 (e.g., empty cached source content, or a zero-length upstream response that somehow passed validation), this causes a division by zero, producing `+Inf` or `NaN` which gets logged and could cause issues with metrics/monitoring systems.
Additionally, in `processFromSourceOrFetch()`, when source data is loaded from cache, `fetchBytes` is set to `int64(len(sourceData))` which will be 0 for empty data, and this is passed to `processAndStore()`.
## Impact
Panics won't occur (Go float division by zero produces Inf), but:
- Log output contains `+Inf` or `NaN` which breaks log parsing
- Metrics systems may reject or mishandle these values
- The underlying issue (empty source) should be caught earlier
## Fix
Add a guard for `fetchBytes == 0` before the division, and also validate that source data is non-empty before attempting to process it.
clawbot
self-assigned this 2026-02-09 00:56:08 +01:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Bug
In
internal/imgcache/service.go,processAndStore()computes a size ratio:When
fetchBytesis 0 (e.g., empty cached source content, or a zero-length upstream response that somehow passed validation), this causes a division by zero, producing+InforNaNwhich gets logged and could cause issues with metrics/monitoring systems.Additionally, in
processFromSourceOrFetch(), when source data is loaded from cache,fetchBytesis set toint64(len(sourceData))which will be 0 for empty data, and this is passed toprocessAndStore().Impact
Panics won't occur (Go float division by zero produces Inf), but:
+InforNaNwhich breaks log parsingFix
Add a guard for
fetchBytes == 0before the division, and also validate that source data is non-empty before attempting to process it.