Skip to content

fix(build): correct libgpod artwork offsets on musl - #84

Open
Twinded wants to merge 1 commit into
jvgomg:mainfrom
Twinded:fix/libgpod-append-offset
Open

Twinded wants to merge 1 commit into
jvgomg:mainfrom
Twinded:fix/libgpod-append-offset

Conversation

@Twinded

@Twinded Twinded commented Nov 6, 2026

Copy link
Copy Markdown

On musl builds, albums end up with another album's artwork once a sync saves the database more than once. podkit doctor still says all checks passed, so you only see it on the iPod.

src/ithumb-writer.c:1065 in libgpod 0.8.3 runs writer->cur_offset = ftell (writer->f) right after fopen (writer->filename, "ab"). C leaves that position up to the implementation: glibc returns the end of the file, musl returns 0. libgpod then records the new thumbnails' offsets starting from 0, so they point at images already in the file. Saves happen every 10 tracks, so a sync of more than 10 tracks can hit this.

The fix adds fseek (writer->f, 0, SEEK_END) before the ftell, in the Linux branch of build-static-deps.sh, with a grep so the build fails if the line ever moves. Changing that file also changes the static-deps cache key. I left the macOS branch alone.

To reproduce without an iPod, sync a few albums with different artwork into a directory that has iPod_Control/Device/SysInfo and SysInfoExtended from a nano 3G, then compare the thumbnails each ArtworkDB entry points at. Same 3 albums and 7 artwork entries on a musl build of abaf519 (Alpine 3.21), for format 1060:

without the fix   offsets 0, 0, 204800, 0, 204800, 0, 0                         all the same image
with the fix      offsets 0, 204800, 409600, 614400, 819200, 1024000, 1228800   3 images, one per album

doctor passes in both cases. On a real iPod nano 3G the artwork was wrong without the fix and right with it, including adding and removing albums and doctor --repair artwork-rebuild -c main. That iPod run used the same substitution applied from a small script, the table above uses this exact diff. I did not run your test suite or a glibc build with this patch, and I did not add a regression test.

I don't know if this explains the corruption described in ADR-013. The diff applies cleanly on build-static-deps.sh from #77 and #83.

Claude (Claude Code) found the cause and wrote this patch. I checked the artwork on the iPod myself.

libgpod reads its thumbnail write offset with ftell right after fopen("ab").
musl reports 0 there, so artwork saved after the first database save points
at images already in the .ithmb file.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant