Skip to content

Fix share extension crash on HD photos#409

Merged
benthecarman merged 1 commit intosledtools:masterfrom
benthecarman:share-fix
Mar 4, 2026
Merged

Fix share extension crash on HD photos#409
benthecarman merged 1 commit intosledtools:masterfrom
benthecarman:share-fix

Conversation

@benthecarman
Copy link
Copy Markdown
Collaborator

@benthecarman benthecarman commented Mar 4, 2026

Summary

  • Fix share extension crash when sharing full-resolution photos by using CGImageSource to downsample directly from file URLs instead of loading the full bitmap into memory
  • A 48MP iPhone photo is ~185MB uncompressed, which exceeds the ~120MB memory limit for app extensions and causes a Jetsam kill

Test plan

  • Share a screenshot to Pika via the share sheet — verify it sends
  • Share a full-resolution photo to Pika — verify it doesn't crash and sends successfully

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Performance & Optimization
    • Improved image handling in the share extension: now prefers URL-based downsampling to avoid loading full images into memory.
    • Added a safe in-memory downsampling path for raw image data as a guarded fallback.
    • Removed the prior full-image-in-memory processing route.
    • Preserves filename derivation from URLs when available and reduces memory use for large shared images.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 4, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

ShareIncomingPayload image loading now prefers URL-based ImageIO downsampling, falls back to Data-based downsampling, and removes the previous in-memory UIImage loading/downscaling path. Adds three private helpers to produce downsampled JPEG data from URL, Data, or CGImageSource; filename derives from URL when present.

Changes

Cohort / File(s) Summary
Image loading & downsampling
ios/ShareExtension/ShareViewController.swift
Reworked image extraction to prefer URL-based downsampling via downsampledJPEGData(from: URL), then Data-based downsampling via downsampledJPEGData(fromData: Data). Added shared helper downsampledJPEGData(from source: CGImageSource, ...). Removed the in-memory UIImage load/downscale path (loadUIImage and downscaledJPEGData(from:)). Filename is derived from URL.lastPathComponent when available.

Sequence Diagram(s)

sequenceDiagram
    participant Provider as ItemProvider
    participant FS as FileURL
    participant Downsampler as DownsampleHelpers
    participant Caller as ShareIncomingPayload.loadImage

    Caller->>Provider: request image item
    alt Provider supplies a file URL
        Provider->>FS: deliver file URL
        FS->>Downsampler: downsample from URL (ImageIO)
        Downsampler->>Caller: return JPEG data + filename(from URL)
    else Provider supplies raw Data
        Provider->>Downsampler: deliver Data
        Downsampler->>Caller: downsample via CGImageSource -> JPEG data + provider name
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through bytes, light on my feet,

URLs first — a tidy treat,
Data next, I chewed with care,
No full images bloating there.
A tiny hop, the payload's neat!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix share extension crash on HD photos' directly addresses the main objective of the PR, which is fixing a crash when sharing full-resolution photos by implementing better image downsampling.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@benthecarman benthecarman changed the title Fix iOS share extension on device Fix share extension crash on HD photos Mar 4, 2026
coderabbitai[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

Use ImageIO (CGImageSource) to downsample images instead of loading
the full bitmap into memory. A 48MP photo is ~185MB uncompressed, which
exceeds the ~120MB memory limit for app extensions.

The image loading now uses a tiered approach:
1. loadFileRepresentation — gets a temp file URL, downsamples via
   ImageIO without ever decoding the full bitmap (preferred path).
2. loadItem URL/Data fallback — same ImageIO downsampling.
3. loadItem UIImage fallback — provider already decoded the bitmap,
   so serialize to JPEG (minimal extra allocation) then downsample.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@benthecarman benthecarman merged commit 73e7cd4 into sledtools:master Mar 4, 2026
18 checks passed
@benthecarman benthecarman deleted the share-fix branch March 4, 2026 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant