-
Notifications
You must be signed in to change notification settings - Fork 0
fix(deps): pin patched heic fork to stop native decode memory leak #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f3f2cff
fix(deps): replace heic with fork commit fixing native decode leak
cursoragent 9270610
docs: document HEIC replace; add optional heicleak RSS test
cursoragent 9571498
test(imaging): warm up HEIC decoder before RSS leak check
cursoragent ac75135
docs: add HEIC leak fix implementation plan
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| //go:build heicleak | ||
|
|
||
| package imaging | ||
|
|
||
| import ( | ||
| "os" | ||
| "runtime" | ||
| "runtime/debug" | ||
| "testing" | ||
|
|
||
| "fyne.io/fyne/v2/storage" | ||
| ) | ||
|
|
||
| func TestHEICDecode_DoesNotGrowRSSUnbounded(t *testing.T) { | ||
| if os.Getenv("PICFETCH_HEIC_LEAK_TEST") == "" { | ||
| t.Skip("set PICFETCH_HEIC_LEAK_TEST=1 to run native RSS check") | ||
| } | ||
|
|
||
| data, err := os.ReadFile("testdata/test_exif.heic") | ||
| if err != nil { | ||
| t.Fatalf("read fixture: %v", err) | ||
| } | ||
| path := writeTempFile(t, "leak.heic", data) | ||
|
|
||
| // Warm libheif/wazero once so one-time init is not counted as per-decode growth. | ||
| if _, err := LoadImage(storage.NewFileURI(path), DefaultImgCacheBytes); err != nil { | ||
| t.Fatalf("warmup decode: %v", err) | ||
| } | ||
| settleRSS() | ||
|
|
||
| const mid = 20 | ||
| for i := 0; i < mid; i++ { | ||
| if _, err := LoadImage(storage.NewFileURI(path), DefaultImgCacheBytes); err != nil { | ||
| t.Fatalf("decode %d: %v", i, err) | ||
| } | ||
| } | ||
| settleRSS() | ||
| rssMid, ok := readRSS() | ||
| if !ok { | ||
| t.Skip("RSS measurement unavailable on this platform") | ||
| } | ||
|
|
||
| const iterations = 20 | ||
| for i := 0; i < iterations; i++ { | ||
| if _, err := LoadImage(storage.NewFileURI(path), DefaultImgCacheBytes); err != nil { | ||
| t.Fatalf("decode %d: %v", mid+i, err) | ||
| } | ||
| } | ||
| settleRSS() | ||
| rssAfter, ok := readRSS() | ||
| if !ok { | ||
| t.Fatal("RSS measurement failed after decode loop") | ||
| } | ||
|
|
||
| // 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 { | ||
| t.Fatalf("RSS grew %d bytes over %d decodes after warmup; want <= %d MB (leak suspected)", growth, iterations, maxGrowthMB) | ||
| } | ||
| } | ||
|
|
||
| func settleRSS() { | ||
| debug.FreeOSMemory() | ||
| runtime.GC() | ||
| debug.FreeOSMemory() | ||
| runtime.GC() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| //go:build heicleak && linux | ||
|
|
||
| package imaging | ||
|
|
||
| import ( | ||
| "os" | ||
| "strconv" | ||
| "strings" | ||
| ) | ||
|
|
||
| func readRSS() (uint64, bool) { | ||
| data, err := os.ReadFile("/proc/self/status") | ||
| if err != nil { | ||
| return 0, false | ||
| } | ||
| for line := range strings.SplitSeq(string(data), "\n") { | ||
| if after, ok := strings.CutPrefix(line, "VmRSS:"); ok { | ||
| fields := strings.Fields(after) | ||
| if len(fields) == 0 { | ||
| return 0, false | ||
| } | ||
| kb, err := strconv.ParseUint(fields[0], 10, 64) | ||
| if err != nil { | ||
| return 0, false | ||
| } | ||
| return kb * 1024, true | ||
| } | ||
| } | ||
| return 0, false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| //go:build heicleak && !linux | ||
|
|
||
| package imaging | ||
|
|
||
| func readRSS() (uint64, bool) { | ||
| return 0, false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 - rssMidoperates onuint64values. If RSS legitimately decreases between the two measurement points (e.g., the OS reclaims pages, orsettleRSSreleases memory from the first batch), the subtraction wraps around to a value nearmath.MaxUint64, which far exceedsmaxGrowthMB*1024*1024. This causes a false test failure reporting "leak suspected" even when there is no leak. A signed comparison or an early-return whenrssAfter <= rssMidwould prevent the wrap.Reviewed by Cursor Bugbot for commit ac75135. Configure here.