Bug: Division by zero in processAndStore when source data is empty #5
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sneak/pixa#5
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.