webp-sh / webp_server_go

Go version of WebP Server. A tool that will serve your JPG/PNG/BMP/SVGs as WebP/AVIF format with compression, on-the-fly.
https://docs.webp.sh
GNU General Public License v3.0
1.79k stars 174 forks source link

Checking if imageHeightWidthRatio is not zero before dividing #269

Closed reward-rabieth closed 1 year ago

reward-rabieth commented 1 year ago

https://github.com/webp-sh/webp_server_go/blob/d9da7f3cd3c1a13cce368a81e15ecab162fd7afd/encoder/encoder.go#L43C4-L48C3

Check if imgHeightWidthRatio is not zero before dividing.

Handle the case where imgHeightWidthRatio is zero (avoid division by zero) You can log an error or take appropriate action

n0vad3v commented 1 year ago

Hmm, this is a little bit weird.

imgHeightWidthRatio := float32(img.Metadata().Height) / float32(img.Metadata().Width), imgHeightWidthRatio seems can only be zero when img.Metadata().Height is zero, and normal image cannot have zero in height.

Do you have an example image that could lead to this problem?

reward-rabieth commented 1 year ago

Thank you for your response. No, I don't have an example image that could lead to this problem. It was indeed just an idea and not based on a specific image-related issue. I appreciate your clarification, and I'm satisfied with the explanation you provided.