Skip to content

fix(metadata): handle ZeroDivisionError in EXIF GPS extraction (#1535) - #1674

Open
Dotify71 wants to merge 1 commit into
AOSSIE-Org:mainfrom
Dotify71:fix/exif-gps-zerodivision
Open

Dotify71 wants to merge 1 commit into
AOSSIE-Org:mainfrom
Dotify71:fix/exif-gps-zerodivision

Conversation

@Dotify71

@Dotify71 Dotify71 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

Corrupted or non-standard image files containing EXIF GPS metadata with rational denominators equal to zero caused _convert_to_degrees to raise an unhandled ZeroDivisionError. Because ZeroDivisionError inherits from ArithmeticError rather than ValueError, the exception was not caught by the except block in _extract_gps_coordinates, causing image_util_extract_metadata to fail and aborting photo scans.

Implementation Details:

  1. Mathematical Edge-Case Handling in _convert_to_degrees:
    • Explicitly checked v.denominator == 0.0 when processing rational EXIF structures and raised ZeroDivisionError with an informative error message.
  2. Exception Handling in _extract_gps_coordinates:
    • Added ZeroDivisionError to the exception tuple in _extract_gps_coordinates so malformed GPS tags fallback gracefully to (None, None) without terminating the broader metadata extraction or image scan.
  3. Unit Tests:
    • Added comprehensive tests in backend/tests/test_extract_location_metadata.py covering zero-denominator rational tuples, valid rationals, and non-rational (plain float/int) coordinates.

Fixes #1535

Gracefully handle corrupted EXIF GPS tags with zero denominators in _convert_to_degrees and catch ZeroDivisionError in _extract_gps_coordinates to prevent backend scanner crashes. Add unit tests for zero denominators and plain float coordinates.
@coderabbitai

coderabbitai Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review: 1
  • dev

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added the bug Something isn't working label Nov 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant