Skip to content

ip/opus: fix opusfile callbacks and fdsan abort on invalid files - #1518

Merged
flyingmutant merged 1 commit into
cmus:masterfrom
pgaskin:fix-opus
Oct 3, 2026
Merged

flyingmutant merged 1 commit into
cmus:masterfrom
pgaskin:fix-opus

Conversation

@pgaskin

@pgaskin pgaskin commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Previously, op_fdopen would overwrite our callbacks with the opusfile stdio ones (cb is an output parameter), and fdopen would take ownership of the fd, making fdsan abort due to it being closed with close (rather than fdclose) (and also leaking the FILE) when an invalid file is open.

Fixing the callbacks also means we need to fix the seek callback since opusfile requires the return to be success/failure, rather than the new offset.

The only notable behaviour difference between our callbacks and the opusfile stdio ones are the read buffering behaviour. Since opusfile reads 2KiB chunks, and most libc implementations (glibc, bionic) use a st_blksize-size buffer (usually 4KiB), this doubles the number of read syscalls. For musl, the syscall count is unchanged since it reads directly, and only uses an internal 1KiB buffer for overflow. At any rate, most other plugins (e.g., vorbis, flac) also use raw i/o too, so it's not really a big deal.

pgaskin/cmus-android#2

Previously, op_fdopen would overwrite our callbacks with the opusfile
stdio ones (cb is an output parameter), and fdopen would take ownership
of the fd, making fdsan abort due to it being closed with close (rather
than fdclose) (and also leaking the FILE) when an invalid file is open.

Fixing the callbacks also means we need to fix the seek callback since
opusfile requires the return to be success/failure, rather than the new
offset.

The only notable behaviour difference between our callbacks and the
opusfile stdio ones are the read buffering behaviour. Since opusfile
reads 2KiB chunks, and most libc implementations (glibc, bionic) use a
st_blksize-size buffer (usually 4KiB), this doubles the number of read
syscalls. For musl, the syscall count is unchanged since it reads
directly, and only uses an internal 1KiB buffer for overflow. At any
rate, most other plugins (e.g., vorbis, flac) also use raw i/o too, so
it's not really a big deal.
@flyingmutant
flyingmutant merged commit 2cf1092 into cmus:master Oct 3, 2026
6 checks passed
@BrewTestBot BrewTestBot mentioned this pull request Oct 28, 2026
1 task done
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