PictoPy icon indicating copy to clipboard operation
PictoPy copied to clipboard

BUG: Unhandled ZeroDivisionError in _convert_to_degrees during EXIF GPS metadata extraction

Open Dotify71 opened this issue 2 months ago • 4 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

What happened?

In backend/app/utils/images.py, the _extract_gps_coordinates() function calls _convert_to_degrees() to convert EXIF DMS tags to decimal degrees:

def _convert_to_degrees(value): def to_float(v): return ( float(v.numerator) / float(v.denominator) if hasattr(v, "numerator") else float(v) )

d, m, s = (to_float(v) for v in value[:3])
return d + (m / 60.0) + (s / 3600.0)

If an image file contains malformed or corrupted EXIF GPS tags with denominator == 0, to_float() raises ZeroDivisionError.

In _extract_gps_coordinates(), the exception handler catches:

except ( KeyError, IndexError, TypeError, ValueError, AttributeError, ): latitude = None longitude = None

Because ZeroDivisionError inherits from ArithmeticError (which is not a subclass of ValueError or TypeError), the exception is not caught by the except block and propagates up, crashing image_util_extract_metadata() and failing the image scan process.

Expected Behavior

Malformed EXIF GPS metadata with zero denominators should be caught gracefully, returning (None, None) for coordinates without crashing the backend image scanner.

Code Location

File: backend/app/utils/images.py (lines 528-583)

Environment Details

  • OS: All
  • Python: 3.11+
  • Backend: FastAPI / PictoPy Backend

What I want

I would like to submit a Pull Request to fix backend/app/utils/images.py by handling zero division exceptions.

Note:

Please do not post AI-generated spam or template comments on this issue.

Record

  • [x] I agree to follow this project's Code of Conduct

Dotify71 avatar Sep 09 '26 06:09 Dotify71

👋 Thanks for opening this issue! The maintainers will review it shortly. Till then, do not open any PR. This is a strict rule we like to follow around here :)

github-actions[bot] avatar Sep 09 '26 06:09 github-actions[bot]

Hi @rohan-pandeyy , I noticed that PR #1537 was linked three weeks ago without the issue being assigned. If that PR is inactive, or if it needs a proper approach that follows the repo guidelines, I'm ready to fix the ZeroDivisionError properly. Could you please assign this issue to me?

nikhilprasad-data avatar Sep 29 '26 10:09 nikhilprasad-data

Hi @rohan-pandeyy , I've reproduced the ZeroDivisionError locally and verified that catching ZeroDivisionError in _extract_gps_coordinates() safely handles malformed metadata by returning (None, None) without crashing the backend.

My local test result is attached below. I have the tested fix ready on a local feature branch, and I'd love to be assigned so I can open a PR .

Image

nikhilprasad-data avatar Sep 29 '26 13:09 nikhilprasad-data

Opened PR #1674 with the fix!

Dotify71 avatar Nov 06 '26 14:11 Dotify71