Skip to content

fix(deps): pin patched heic fork to stop native decode memory leak - #7

Merged
frathe merged 4 commits into
mainfrom
cursor/heic-leak-fix-ee22
Aug 27, 2026
Merged

fix(deps): pin patched heic fork to stop native decode memory leak#7
frathe merged 4 commits into
mainfrom
cursor/heic-leak-fix-ee22

Conversation

@frathe

@frathe frathe commented Aug 26, 2026

Copy link
Copy Markdown
Owner

What does this change do, and why?

github.com/gen2brain/heic v0.7.1 leaks native libheif memory on every still-image decode (heif_decode_image without heif_image_releasegen2brain/heic#15). Go heap stays flat, so this is invisible to routine profiling but RSS grows without bound when browsing HEIC-heavy folders.

Upstream fix is in gen2brain/heic#16 (authored from this project) but not yet released. This PR adds a go.mod replace to frathe/heic@0ac0a39 (PR head), documents the pin in AGENTS.md, notes the mitigation in needs_refactoring.md, and adds an optional -tags=heicleak RSS regression test for manual/local use.

How was this tested?

  • go list -m github.com/gen2brain/heic confirms replace → frathe/heic@0ac0a39
  • go test -race -run 'TestLoadImage|TestReadMetadata_HEIC' ./internal/imaging/...
  • PICFETCH_HEIC_LEAK_TEST=1 go test -tags=heicleak -run TestHEICDecode_DoesNotGrowRSSUnbounded ./internal/imaging/... (PASS on linux)
  • make fmt-check, go vet ./..., go build ./...
  • go test -timeout 20m -race ./... (all packages PASS)

Checklist

  • make fmt-check is clean, go vet ./... and go test -timeout 20m -race ./... pass
  • User-visible strings go through lang.L, with the key added to every bundle in translations/ (N/A — dependency/docs only)
  • internal/ui/help/manual.md and manual_de.md updated, if this changes documented behavior (N/A)
  • ARCHITECTURE.md updated, if this changes the package structure (N/A)
  • No new TODO/FIXME comments — open items go in todos.md instead

Follow-up

Remove the replace and bump github.com/gen2brain/heic once upstream tags a release containing PR #16.

Open in Web Open in Cursor 

cursoragent and others added 4 commits August 26, 2026 22:56
Co-authored-by: Florian Rathe <frathe@users.noreply.github.com>
Co-authored-by: Florian Rathe <frathe@users.noreply.github.com>
Co-authored-by: Florian Rathe <frathe@users.noreply.github.com>
Co-authored-by: Florian Rathe <frathe@users.noreply.github.com>
@frathe
frathe marked this pull request as ready for review August 27, 2026 07:32
@frathe
frathe merged commit f28a0df into main Aug 27, 2026
7 checks passed
@frathe
frathe deleted the cursor/heic-leak-fix-ee22 branch August 27, 2026 07:34

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ac75135. Configure here.

// With the upstream leak, RSS climbs roughly linearly with decode count.
// After PR #16 the second batch should not add much beyond wasm init noise.
const maxGrowthMB = 80
if growth := rssAfter - rssMid; growth > maxGrowthMB*1024*1024 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unsigned subtraction wraps on RSS decrease causing false failure

Medium Severity

growth := rssAfter - rssMid operates on uint64 values. If RSS legitimately decreases between the two measurement points (e.g., the OS reclaims pages, or settleRSS releases memory from the first batch), the subtraction wraps around to a value near math.MaxUint64, which far exceeds maxGrowthMB*1024*1024. This causes a false test failure reporting "leak suspected" even when there is no leak. A signed comparison or an early-return when rssAfter <= rssMid would prevent the wrap.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ac75135. Configure here.

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.

2 participants